开发者

xpath select inner text of an element which is repeated in random area of a xml file

开发者 https://www.devze.com 2023-02-17 02:13 出处:网络
I have a xml file like this NEVER MINDE letter cases. I am interested in elements that are insideand ...and if there is aelement in a subchild ofI dont want to count taht in.

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消