Let's start - method Match $(File file) seems to be good entry point. Now I need file for testing - the nearest one is my pom.xml - why not? :)

public class JooxSandbox { public static void main(String[] args) throws IOException, SAXException { Match document = $(new File("pom.xml")); } }

Without any exceptions - great :) Let's move on and get first node!

System.out.println("JOOX rocks!"); // get tag name System.out.println(document.tag()); // get tag attribute System.out.println(document.attr("xmlns"));

Compile, run and there's an output:

JOOX rocks! project http://maven.apache.org/POM/4.0.0

Cool - another battle won. Now something more complex - iterating over dependencies should be ok. Match dependencies = document.find("dependency"); System.out.println("Found dependencies:" + dependencies.size()); for (Match dependency : dependencies.each()) { System.out.println(Joiner.on(':').join( dependency.find("groupId").content(), dependency.find("artifactId").content(), dependency.find("version").content())); } produces Dependencies count: 2 com.google.guava:guava:13.0 org.jooq:joox:1.1.0



API is in fact quite easy, and if you prefer all the time exposing original elements (like org.w3c.dom.Element by calling get() method instead of the each()). In addition to finding elements we can perform filtering. For example if we want to retrive just even dependencies:

// even() is static method from JOOX class dependencies.filter(even()).each();

But so far we're just reading existing content. Why stop there? I've got such project metadata:

pl.kuba.sandbox sandbox 1.0



document.xpath("//version") .content("1.0.1-SNAPSHOT") .after("

\t My Sandbox "); System.out.println(document.content()); And voila:

pl.kuba.sandbox sandbox 1.0.1-SNAPSHOT My Sandbox

We can change it by typing:

Notice that JOOX is operating on independent document, and if you want to save results you've to manually flush document.content() into file (or maybe I've overlooked something?). Anyway, I hope you'll enjoy it! For me it's the only one for parsing and modifying on XML in Java :)

Some useful links: