Xnav is a library designed for seamless navigation and querying of XML documents, inspired by the simplicity and elegance of XPath. With Xnav, developers can easily traverse and extract information from XML structures.
The library is available on Maven Central. To add it to your project, include
the following snippet in your pom.xml:
<dependency>
<groupId>com.github.volodya-lombrozo</groupId>
<artifactId>xnav</artifactId>
<version>0.1.18</version>
</dependency>Xnav provides a fluent API for navigating and querying XML. Here's a basic example of how to use it:
import com.github.lombrozo.xnav.Xnav;
public final class XnavUsage {
public static void main(String[] args) {
System.out.println(
new Xnav("<root><item key='value'/></root>")
.element("root")
.element("item")
.attribute("key")
.text()
.orElse("default")
); // Output: value
}
}The library not only provides an intuitive API but also addresses performance issues that arise when using XPath on large XML files. Below is one example of how Xnav can outperform other libraries:
| Library | XPath Expression | Execution Time (ms) |
|---|---|---|
| Saxon | /program/@name |
255.63 |
| Jaxen | /program/@name |
46.57 |
| JAXP | /program/@name |
75.10 |
| Xnav | .element('program').attribute('name') |
2.80 |
You can find more benchmarks here.
To build the library from source, clone the repository and run the following command in the root directory:
mvn clean installTo run the tests, use the following command:
mvn testAlso, you might want to update examples in the README file. To do this, run:
mvn process-resources -PdocsTo run benchmarks, use the following command:
mvn clean verify -Pbenchmark -DskipTestsFork repository, make changes, send us a pull request. We will review your
changes and apply them to the main branch shortly, provided they don't violate
our quality standards. To avoid frustration,
before sending us your pull request, please run full Maven build:
$ mvn clean install -PquliceYou will need Maven 3.3+ and Java 11+ installed.