我想在解析本地 XML 之前显示数据但不知道怎么做?我用这个试过了
XDocument loadedData = XDocument.Load("People.xml");
var data = from query in loadedData.Descendants("array")
select new Person {
Name = (string)query.Element("string"),
};
listBox1.ItemsSource = data;
但它只向我展示了一个元素。
XML 是:
<?xml version="1.0" encoding="UTF-8"?>
<dict>
<key>Categories</key>
<array>
<string>Playing baseball</string>
<string>Driving a car</string>
<string>Getting dressed</string>
<string>Eating a hamburger</string>
<string>Tying shoelace</string>
</array>
</dict>
我想解析所有字符串元素。