xml - How to grab element by index when elements have different parents -
this question has answer here:
i trying grab elements of index 3 , 4 in following xml:
<automated> <group> <test><id>testid</id>...</test> <test>...</test> <test>...</test> <!-- 3? --> </group> <test>...</test> <!-- 4? --> </automated>
as far aware, expression //x
used grab elements type x
. expression attempting use grab 3rd , 4th elements is:
//test[3] , //test[4]
however, element //test[4]
not return anything. upon further investigating, i've realized //test[1]
return both elements 1 , 4. first child of first element, , second (first test?) child.
is there way achieve want do?
the other thing can think of (since i'm using in c# , have access scripting this) using counter iterate through possible selections of //test[x] , index myself. however, seems more work necessary.
as turns out, 1 can use parentheses fix issue, xpath use precedence.
(//test)[4]
will give me fourth element of test elements in xml document, whereas
//test[4]
does not exist in document, there no element 4 total test children.
Comments
Post a Comment