我想在解析本地 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>