How should my class look like to serialize to/from a XML like this
<root>
<MyCollection ColDetails="val1">
<Col_Obj>
<Prop1>xxxx</Prop1>
<Prop2>xxxx</Prop2>
</ColObj>
<Col_Obj>
<Prop1>xxxx</Prop1>
<Prop2>xxxx</Prop2>
</ColObj>
</MyCollection>
</root>
...this one -> ColDetails="val1"
or
<root>
<MyCollection>
<ColDetails>val1</ColDetails>
<Col_Obj>
<Prop1>xxxx</Prop1>
<Prop2>xxxx</Prop2>
</ColObj>
<Col_Obj>
<Prop1>xxxx</Prop1>
<Prop2>xxxx</Prop2>
</ColObj>
</MyCollection>
</root>
...this one -> <ColDetails>val1</ColDetails>
C# Class
public string ColDetails { get; set; }
public List<Col_Obj> MyCollection { get; set; }
public class Col_Obj
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}
Prefer to serialize with System.Xml.Serialization
.
I can easily specify two properties as an XML attribute with value using [XmlAttribute]
and [XmlText]
, that's half the way I assume?