I have two serializable objects:
[Serializable]
public class A
{
[XmlArray("Items")]
[XmlArrayItem]
public UnitItem[] Items{get;set;}
......
}
[Serializable]
public class UnitItem
{
[XmlAttribute]
public string Name { get; set; }
[XmlText]
public string Data { get; set; }
}
I can serialize A as:
<Items>
<UnitItem Name="AAA">balabala</UnitItem>
<UnitItem Name="BBB">bulubulu</UnitItem>
......
</Items>
but now I want to create an XML structure as follows:
<Items>
<AAA>balabala</AAA>
<BBB>bulubulu</BBB>
......
</Items>
that is , I expected that ElementNameof XmlArrayItemis the value of the member variable, not the name of the variable . How can i do this?
If I need to inherit ISerializable, can you tell me how to implement it?
source
share