0
votes

My sample input XML is:

<root>
    <a>
    <b>
    <c>item1</c>
    <d>item2</d>
    <e>item3</e> 
    </b>
    </a>
    <a>
    <b>
    <c>item4</c>
    <c>item5</c>
    <e>item6</e>   
    </b>        
    </a>
    </root>

I am suppose to select all the first occurrence of node c. The output should be item1 and item4. when I am using /root/a/b/c it returns item1,item4 and item5.

2
Try /root/a/b/c[0]. Otherwise show some more of what you're trying (e.g. code). - Thomas
where tag b is closing? - Vitaliy
stackoverflow.com/questions/14294997/… here only the first element is selected.I want to select all the first occurrence of node c. - ranjit singh

2 Answers

1
votes

I used this for your example //root//c[1] and it's working as you expect. enter image description here

0
votes
/root/a/b/c[1]

For more detailed explanation see: https://stackoverflow.com/a/5818966/36305