在 Windows Phone 中解析复杂的 XML
本文关键字:复杂 XML Windows Phone | 更新日期: 2023-09-27 18:33:26
我想在解析本地XML之前显示数据,但不知道如何?我 用这个试过了
XDocument loadedData = XDocument.Load("Record.xml"); var data = from
query in loadedData.Descendants("item")
select new Person {
Name = (string)query.Element("record"),
}; listBox1.ItemsSource = data;
但它只向我显示一个元素,而不显示标题名称。
XML 是:
<root>
<item name="Title 1">
<record>record1</record>
<record>record2</record>
</item>
<item name="Title 2">
<record>record1</record>
<record>record2</record>
</item>
</root>
检查此代码:
XDocument loadedData = XDocument.Load("Try.xml");
var data = from query in loadedData.Descendants("item")
from a in query.Elements("record")
select new Person
{
Name = (string)a.Value
};
var array = data.ToArray();