xml parsing using xpath.js

Following is the structure of XML I am working on:

      <A>
        <B>
          <C>
            <D>some data</D>
            <D>some data</D>
          </C>
        </B>
        <B>
          <C>
            <D>some data</D>
          </C>
        </B>
      </A>

I am using xpath.js to parse this XML.Here are the scenarios

1.

      select(xmlData, "//B[1]//D");//length is 2.contains D tags within first B
      select(xmlData, "//B[1]//D");//length is 1.contains D tags within second B

2.

      select(xmlData, "//C[1]//D");//length is 3.contains all D tags
      select(xmlData, "//C[2]//D");//this is undefined.

What is the difference between above stated approaches to obtain D tags as array and why is the output different?


Source: javascript

Leave a Reply