我正在为 windows phone 的应用程序解析 xml。我的 XML 看起来像这样:
<?xml version="1.0" encoding="utf-8" ?>
<people>
<person name="Kurt Cobain">
<overall>
</overall>
<childhood>
</childhood>
<youth>
</youth>
<picture1>
</picture1>
</person>
</people>
我应该得到人物节点元素的名称(整体、童年、青年等),因为对于每个人物节点,它们都会有所不同。到目前为止,这是我的代码,但查询结果为空:
XDocument loadedXml = XDocument.Load("people.xml");
var data = from query in loadedXml.Descendants("person")
where ((query.Attribute("name").Value as string).Equals("Kurt Cobain"))
select query.Elements();
string test = "";
foreach (var item in data)
{
test + = (item as XElement).Name.LocalName;
}
MessageBox.Show(test);