如何将 XML 反序列化为对象:
<Root>
<Element Attr="AttrValue1">BodyValue1</Element>
<Element Attr="AttrValue2">BodyValue2</Element>
<Element Attr="AttrValue3">BodyValue3</Element>
</Root>
我需要具有适当属性的精确对象结构。
我试过了:
[XmlRoot("Root")]
public class EventFieldsRoot
{
[XmlElement("Element")]
public List<Element> Elements{ get; set; }
}
public class Element
{
[XmlAttribute]
public string Attr { get; set; }
[XmlElement("")]
public string Body { get; set; }
}
该属性反序列化良好,但主体为空。我怎样才能反序列化身体?
Simply
public class Element
{
[XmlAttribute]
public string Attr { get; set; }
[XmlText]
public string Body { get; set; }
}
XmlText 属性效果非常好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)