how to set the length in an xml file?

how to set the length in an xml file?



I need to set the length of the ContractId field to 25 max. how can I do that?
in other way can I use the substring and how can I use I tried to use it but it works find when the field has value but when the field has no value it throws error so I wonder how can I use substring without causing this error.


new XElement(ns + "projectInfo",
new XElement(ns + "awardingBody", string.Empty),
new XElement(ns + "contractAgencyID", String.Empty),
new XElement(ns + "contractAgency", IsLcpCertified ? (certStatusRecord.ContractorProject.IsSub == true ?
certStatusRecord.ContractorProject.PrimeContractorName : certStatusRecord.ContractorProject.AwardingAgency) :
certStatusRecord.ContractorProject.PrimeContractorId == null ? accountName : certStatusRecord.ContractorProject.PrimeContractor.Name),
new XElement(ns + "projectName", ""),
new XElement(ns + "projectID", certStatusRecord.Project.DIRProjectId),
new XElement(ns + "awardingBodyID", ""),
new XElement(ns + "projectNum", ""),
new XElement(ns + "contractID", **certStatusRecord.ContractorProject.ContractId**),
new XElement(ns + "projectLocation",
new XElement(ns + "description", ""),
new XElement(ns + "street", ""),
new XElement(ns + "city", ""),
new XElement(ns + "county", ""),
new XElement(ns + "state", ""),
new XElement(ns + "zip", ""))),
new XElement(ns + "payrollInfo",
new XElement(ns + "statementOfNP", certStatusRecord.Performing == "YES" ? false : true),






Please show us what you tried, and the error you got when you tried it. Also tell us the data type of certStatusRecord.ContractorProject.ContractId.

– Dour High Arch
Sep 9 '18 at 18:53



certStatusRecord.ContractorProject.ContractId






Are you using a schema? String.Empty should work when there is no schema. So the error must be coming from a schema.

– jdweng
Sep 9 '18 at 20:13






the field is (varchar (50), null)

– Nivo
Sep 10 '18 at 16:01




0



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.