Home > Back-end >  adding attributes to elements
adding attributes to elements

Time:07-28

I am seralising a C# class into an xml, all good except the namespace attributes are not getting inserted into the xml file.

tried the following above the Document as well as the Documents property:

[XmlAttribute("xmlns:xsi",Namespace ="www.test.com")] 
[XmlAttribute("xsi:type",Namespace ="somename")]

but that didn’t work :(

The xml I want to appear in the xml file is:

<someOtherElement></someOtherElement>
<someOtherElement></someOtherElement>
<Documents>
   <Document xmlns:xsi="www.test.com" xsi:type=“somename”>
   <Name></Name>
   <DOB></DOB>
   </Document>
</Documents>
<someOtherElement></someOtherElement>
<someOtherElement></someOtherElement>

Would love any feedback. Thanks!

CodePudding user response:

The following worked for the "somename" attribute:

[xmlAttribute(Namespace = 
 System.Xml.Schema.XmlSchema.InstanceNamespace)]
 public string someAttr {get;set} = "somename"

however still figuring out the xmlns:xsi attribute

  • Related