JDK9 project: XML/JAXP Approachability / Ease of Use

Lukas Eder lukas.eder at datageekery.com
Wed Jun 25 07:18:25 UTC 2014


Hello,

At Data Geekery GmbH, we've been trying to tackle the problems you're outlining with our jQuery port "jOOX"

- https://code.google.com/p/joox/
- https://github.com/jOOQ/jOOX

Unfortunately, we hadn't pushed this very much so far, which is why the API is not very well documented.

The idea is that jQuery is a great way to manipulate the HTML DOM, so we thought why don't we create a similar API for the XML DOM. Our main focus was to:

- Stick with the standards, i.e. not to create any "improved" DOM API like other libraries
- Integrate with XSLT, XPath, JAXB
- Implement all the functional aspects of jQuery

This allows for using jOOX just as a thin wrapper around all the existing, rock-solid libraries.

So, the suggestion you've made in your previous E-Mail:

         String company =
             XMLDocument.fromFile(FILEPATH + "results.xml")
.evalXPath("/Results/Row[USERID=2]/NAME[text()]");
         System.out.printf("Company: %s%n", company);

Would translate to this jOOX statement:

        String company = $("results.xml")
            .xpath("/Results/Row[USERID=2]/NAME[text()]")
            .text();

In our opinion, the strengths of jOOX appear specifically compelling when working with Java 8, as we've outlined in this blog post:
http://blog.jooq.org/2014/01/17/java-8-friday-goodies-lambdas-and-xml/

Some code examples:

// Example 1
$(new File("./pom.xml")).find("groupId")
                        .each(ctx -> {
    System.out.println(
        $(ctx).text() + ":" +
        $(ctx).siblings("artifactId").text() + ":" +
        $(ctx).siblings("version").text()
    );
});

// Example 2
$(new File("./pom.xml"))
    .find("groupId")
    .filter(ctx -> $(ctx).siblings("version")
                         .matchText(".*-SNAPSHOT")
                         .isEmpty())
    .each(ctx -> {
        System.out.println(
        $(ctx).text() + ":" +
        $(ctx).siblings("artifactId").text() + ":" +
        $(ctx).siblings("version").text());
    });

// Example 3
$(new File("./pom.xml"))
    .find("groupId")
    .filter(ctx -> $(ctx).siblings("version")
                         .matchText(".*-SNAPSHOT")
                         .isEmpty())
    .content(ctx ->
        $(ctx).text() + ":" +
        $(ctx).siblings("artifactId").text() + ":" +
        $(ctx).siblings("version").text()
    )
    .rename("artifact")
    .each(ctx -> System.out.println(ctx));

If this is interesting for the JAXP maintainers, I'll be happy to provide more information.

Best Regards,
Lukas

--
Lukas Eder - Head of R&D | lukas.eder at datageekery.com | +41 44 586 82 56
Data Geekery GmbH | Binzstrasse 23 | CH-8045 Zürich | Switzerland

http://www.datageekery.com | Get back in control of your SQLT



More information about the discuss mailing list