【发布时间】:2014-02-26 19:35:00
【问题描述】:
反序列化 XML、XMLElement、XMLAttribute
XML:
<PET>
<RES>Correct</RES>
<PC version="1.1">
<MESSAGE conf="1">SMS</DESC>
<URL>www.google.com</URL>
</PC>
<PRU>200</PRU>
</PET>
类:
[XmlRoot("PET")]
public class Prueba
{
[XmlElement("RES")]
public string Res { get; set; }
[XmlElement("PRU")]
public string Pru { get; set; }
//PC Attribute
//MESSAGE element AND Attribute
//URL element
}
方法:
public void Prueba()
{
Prueba p = new Prueba();
XmlSerializer serializer = new XmlSerializer(p.GetType());
using (StreamReader reader = new StreamReader("Repositories/Local/Prueba.xml"))
{
p = (Prueba)serializer.Deserialize(reader);
}
}
如何读取属性<PC>、MESSAGE元素(属性太)和URL?
【问题讨论】:
-
使用 Visual Studio 的 XSD.exe 实用程序从您的 xml 中创建 c# 类。
标签: c# xml windows-phone-8 deserialization