I have the following C# class property:
private List<string> _accountTypes;
[XmlArray(ElementName = "accountTypes")]
public List<string> AccountTypes
{
get { return _accountTypes; }
set { _accountTypes = value; }
}
which is initialized like this in the class constructor:
_accountTypes = new List<string>( new string[] { "OHGEE", "OHMY", "GOLLY", "GOLLYGEE" });
When deserialized I get this:
<accountTypes>
<string>OHGEE</string>
<string>OHMY</string>
<string>GOLLY</string>
<string>GOLLYGEE</string>
</accountTypes>
I should like it if I could get this:
<accountTypes>
<accountType>OHGEE</accountType>
<accountType>OHMY</accountType>
<accountType>GOLLY</accountType>
<accountType>GOLLYGEE</accountType>
</accountTypes>
Without creating a subclass of type "accountType", how can this be done? Are there any XML attribute properties that can be used to get what I need?
I think you are searching for the [XmlArrayItem]
Attribute.
Try this:
[XmlArray(ElementName = "accountTypes")]
[XmlArrayItem("accountType")]
public List<string> AccountTypes
{
get { return _accountTypes; }
set { _accountTypes = value; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With