如何从XPathNodeiterator获取元素值?
-
10-10-2019 - |
题
当我尝试编码时,
XPathNodeIterator it;
string selectStr = "Equipment/Group/item";
it = nav.Select(selectStr);
while (it.MoveNext())
{
String strVal = "";
if (it.Current.HasChildren)
{
strVal = it.Current.Value.ToString(); // get wrong value here. I want to get 'COM' and 'MD'
}
}
我的XML文件
<Equipment xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<License licenseId="" licensePath=""/>
<Group>
<item>
<key>COM</key>
<value>
<format>10</format>
<value>0</value>
</value>
</item>
<item>
<key>MD</key>
<value>
<format>20</format>
<value>test</value>
</value>
</item>
.....
我发现我使用的时候 while
循环的方法所有XML文件都非常方便。
但是我不知道如何在上述定义XPathNodeiterator时建立关系以获取元素值?
实际上,我需要借助XPathNodeiterator读取整个XML文件。
不隶属于 StackOverflow