I have a web service that has an input object similar to the following.
public class MyInput { [System.Xml.Serialization.XmlArrayItem('Demographic')] public DemographicsInfo[] Demographics {get; set;} }
With the definition of the DemographicsInfo class like this.
public class DemographicsInfo { [System.Xml.Serialization.XmlAttributeAttribute()] public string Name { get; set; } public string Value { get; set; } }
Right now this generates an XML structure like this.
<Demographics> <Demographic Name='String'> <value>string</value> </Demographic> <Demographic Name='String'> <value>string</value> </Demographic> </Demographics>
I need to get it into this
<Demographics> <Demographic Name='String'>string</Demographic> <Demographic Name='String'>string</Demographic> </Demographics>
For the life of me, I cannot seem to find the proper attribute(s) to apply to get this format. Does anyone have any advice?
If you know the structure you want, the simplest option is to work back from the xml; write the xml into a file (
foo.xmlin my case), then (at the command line):Then look at
foo.csto see how it can be done; it turns out that you simply mark the value with[System.Xml.Serialization.XmlTextAttribute()].Here’s the xsd output: