Reputation: 14149
I've following xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sndbox</groupId>
<artifactId>joox-test</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>joox</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>
</dependencies>
</project>
Now I want to find version tag, but only on the root level of the document (project version = 1.0.0). When i use find("version")
it works like xpath("//version")
and returns tags from whole document, and I need equivalent of the xpath("version")
method.
Any ideas?
Upvotes: 2
Views: 182
Reputation: 221125
You have a couple of options to fetch the /project/version tag:
$(doc).xpath("/project/version");
$(doc).child("version"); // matches the first
$(doc).children("version"); // matches all
Upvotes: 2