How can I get element value from XPathNodeIterator?
-
10-10-2019 - |
Pergunta
When I try to code as this,
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'
}
}
My Xml File as this
<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>
.....
I found when I use while
method to loop all the xml file is very convenient.
But I don't know how to establish the relation to get element value when I defined an XPathNodeIterator as above?
Actually, I need read the whole Xml file with the aid of XPathNodeIterator.
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow