C# xml序列化与反序列化(转)
以下为将被序列化的类Entity:
[XmlRoot("Root")]
public class Entity
{
[XmlAttribute(AttributeName = "Attr1")]
public string Attribute1;
[XmlElement("SecondLevel")]
public SecondLevel SecondLevel;
public override string ToString()
{
return Serializer.Serialize(this);
}
}
public class SecondLevel
{
[XmlElement("ThirdLevel")]
public List<ThirdLevel> ThirdLevel;
}
public class ThirdLevel
{
[XmlAttribute(AttributeName = "Attribute1")]
public string Attribute1;
[XmlAttribute(AttributeName = "Attribute2")]
public string Attribute2;
[XmlElement("Ele1")]
public Element Ele1;
}
public class Element
{
[XmlAttribute(AttributeName = "Attr1")]
public string Attribute1;
[XmlText]
public string Value;
}
浙公网安备 33010602011771号