Nullpointerection
Nullpointerection

Reputation: 37

XPath for multiple predicates

I have a XML for eg.

<a>
  <b>
    <c/>
    <c/>
    <c/>
  </b>
</a>

I would like to fetch only 1st and 3rd child of tag: To fetch a single child i'm using XPATH as.//a/b/c[1] Can i fetch both [1] and [3] nodes with a single path without iterating over the parent node?

Upvotes: 1

Views: 548

Answers (1)

Robert F.
Robert F.

Reputation: 465

You could use this

.//a/b/c[position() = 1 or position() = 3]

Upvotes: 1

Related Questions