I am the founder and CEO of Data Geekery GmbH, located in Zurich, Switzerland. With our company, we have been selling database products and services around Java and SQL since 2013. Ever since my Master's studies at EPFL in 2006, I have been fascinated by the interaction of Java and SQL. Most of this experience I have obtained in the Swiss E-Banking field through various variants (JDBC, Hibernate, mostly with Oracle). I am happy to share this knowledge at various conferences, JUGs, in-house presentations and on our blog. Lukas is a DZone MVB and is not an employee of DZone and has posted 241 posts at DZone. You can read more from them at their website. View Full User Profile

jOOX - an early prototype for a jQuery port to Java

08.12.2011
| 2055 views |
  • submit to reddit

jQuery is probably one of the most successful API's for the navigation and manipulation of XML data. Unfortunately, that library only exist in JavaScript, mainly for the handling of HTML data. Nevertheless, it would be very well suited as a wrapping layer on top of the Java DOM API, for instance. Incredibly, no one seems to have ported this library to other languages, except maybe for GQuery, which seems to be quite tightly coupled to GWT:

http://timepedia.blogspot.com/2008/04/gwt-road-to-15-language-features-and.html

I have given this a shot and hacked the most important traversing and manipulation functionality together in a rapid prototype (without all the fancy selectors, for now). This prototype looks quite promising:

http://code.google.com/p/joox

Essentially, jOOX code will look similar to this:

// Find the order at index four and add an element "paid"
$(document).find("orders")
             .children()
             .eq(4)
             .append("<paid>true</paid>");

// Find those orders that are paid and flag them as "settled"
$(document).find("orders")
             .children()
             .find("paid")
             .after("<settled>true</settled>");

 

I think it is about time, that Java developers can manipulate XML with the ease of a jQuery programmer. We have suffered a lot with the standard DOM API. History has not brought up any real alternatives (dom4j, JDOM). While their API's seem a bit slimmer, they do not really outperform Xerces:

http://stackoverflow.com/questions/6996013/a-nice-java-xml-dom-utility/7007435#6998870

So let's try afresh with this sexy fluent-ness. Contributions and other feedback welcome! :-)

Note: I am aware of these two projects:

 Unfortunately, both of them are tightly coupled with HTML/CSS. They might inspire jOOX for future developments, though.

0
Published at DZone with permission of Lukas Eder, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)