I have a xml file like this NEVER MINDE letter cases. I am interested in elements that are inside and ...and if there is a element in a subchild of I dont want to count taht in.
<document>
<tests>
<group>
<number>
<random>
....
....
<pins>
<pin>
<number>1</number>
</pin>
<pin>
<number>2</number>
开发者_开发技巧 <result>
<number>NOT INTERESTED</number>
</result>
</pin>
</pins>
</random>
</number>
</group>
I worte the following methods to get the pins that I am interested(in this case 1 and 2)
public int GetNumberOfAllPins()
{
string xpath = "count(/Document//Pins/Pin/Number)";
int num = Convert.ToInt32(nav.Evaluate(xpath));
return num;
}
public string[] GetNameOfAllPins()
{
string[] temp = new string[GetNumberOfAllPins()];
XPathNodeIterator it = nav.Select("/Document//Pins/Pin/Number");
int i = 0;
while (it.MoveNext())
{
temp[i] = it.Current.Value;
i++;
}
return temp;
}
But these codes gives me strange results sometimes less or more elements that I am interested in. Would you mind givng some tips?
Thanks.
Sorry for bothering but I fount the problem. there were some adjacent elements in my XML file. this codes works good!
精彩评论