我是XML的新手^ _ ^
<a>
<book>
<c>
<e>Val1</e>
</c>
<d>val2</d>
</book>
<book>
<c>
<e>Val3</e>
</c>
<d>val4</d>
</book>
Run Code Online (Sandbox Code Playgroud)
问题是我需要先使用每本书内的价值
XmlNodeList xnList = xDoc.SelectNodes("/a/book");
Run Code Online (Sandbox Code Playgroud)
问题是节点"c"有子"e"所以我不能得到它的值,就像我直接从节点"d"
foreach (XmlNode xn in xnList)
{
string Name = xn["e"].InnerText; // Can't get its value
string Detail = xn["d"].InnerText;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
您需要在节点下选择子<book>节点:
XmlNodeList xnList = xDoc.SelectNodes("/a/book");
foreach (XmlNode xn in xnList)
{
XmlNode eNode = xn.SelectSingleNode("c/e");
if(eNode != null)
{
string Name = eNode.InnerText;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5153 次 |
| 最近记录: |