Given an XML structure that countains both attributes and element values, how do I construct my C# classes using the System.Xml.Serialization attributes?
My XML looks like this:
<Accounts>
<Number credit="1000">100987654321</Number>
<Number credit="0" >100987654322</Number>
<Accounts>
I have been trying with this class structure, but it does not accept the XML.
public class Customer
{
[DataMember, XmlArrayItem(ElementName = "Accounts")]
public AccountNumber[] AccountNumbers;
}
public class AccountNumber
{
[DataMember, XmlElement(ElementName = "Number")]
public string AccountNumber;
[DataMember, XmlAttribute(AttributeName = "credit")]
public int Credit;
}
The trick is to NOT have an array of numbers nested in the "Number" element. We often see this construct in eg. html tags, where you have a tag with some styling perhaps, and the the actual value in between the
"... height=12px> value </..."