XML : xpath match without "complicated expressions"

Assuming the following XML

  <project>    <dependencies>      <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>4.10</version>      </dependency>      <dependency>        <groupId>javax.mail</groupId>        <artifactId>mail</artifactId>        <version>1.4.5</version>      </dependency>    </dependencies>  </project>    

I am attempting to select the node <version>4.10</version> that belongs to junit.

I have succeeded in selecting the element using an xpath tester, using the expression:

  /project/dependencies/dependency/artifactId[text()='junit']/../version    

however, it appears the library I am using does not recognize the .. parent selector.

I've also tried

  /project/dependencies/dependency/artifactId[text()='junit']/following-sibling::version    

which worked for my tester as well, but again, this is a complicated expression (hence the following-sibling::).

Is there a way I can accomplish selecting this element using only "simple expressions?"

No comments:

Post a Comment