What Java XML library do you recommend (to replace dom4j)? [closed] What Java XML library do you recommend (to replace dom4j)? [closed] xml xml

What Java XML library do you recommend (to replace dom4j)? [closed]


Sure, XOM :-)

XOM is designed to be easy to learn and easy to use. It works very straight-forwardly, and has a very shallow learning curve. Assuming you're already familiar with XML, you should be able to get up and running with XOM very quickly.

I use XOM for several years now, and I still like it very much. Easy to use, plenty of documentation and articles on the web, API doesn't change between releases. 1.2 was released recently.

XOM is the only XML API that makes no compromises on correctness. XOM only accepts namespace well-formed XML documents, and only allows you to create namespace well-formed XML documents. (In fact, it's a little stricter than that: it actually guarantees that all documents are round-trippable and have well-defined XML infosets.) XOM manages your XML so you don't have to. With XOM, you can focus on the unique value of your application, and trust XOM to get the XML right.

Check out web page http://www.xom.nu/ for FAQ, Cookbook, design rationale, etc. If only everything was designed with so much love :-)

Author also wrote about What's Wrong with XML APIs (and how to fix them). (Basically, reasons why XOM exists in the first place)

Here is also 5-part Artima interview with author about XOM, where they talk about what's wrong with XML APIs, The Good, the Bad, and the DOM, A Design Review of JDOM, Lessons Learned from JDOM and finally Design Principles and XOM.


The one built into the JDK ... with a few additions.

Yes, it's painful to use: it is modeled after W3C specs that were clearly designed by committee. However, it is available anywhere, and if you settle on it you don't run into the "I like Dom4J," "I like JDOM," "I like StringBuffer" arguments that come from third-party libraries. Especially since such arguments can turn into different pieces of code using different libraries ...

However, as I said, I do enhance slightly: the Practical XML library is a collection of utility classes that make it easier to work with the DOM. Other than the XPath wrapper, there's nothing complex here, just a bunch of routines that I found myself rewriting for every job.


I've been using XMLTool for replacing Dom4j and it's working pretty well.

XML Tool uses Fluent Interface pattern to facilitate XML manipulations:

XMLTag tag = XMLDoc.newDocument(false)   .addDefaultNamespace("http://www.w3.org/2002/06/xhtml2/")   .addNamespace("wicket", "http://wicket.sourceforge.net/wicket-1.0")   .addRoot("html")   .addTag("wicket:border")   .gotoRoot().addTag("head")   .addNamespace("other", "http://other-ns.com")   .gotoRoot().addTag("other:foo");System.out.println(tag.toString());

It's made for Java 5 and it's easy to create an iterable object overselected elements:

for (XMLTag xmlTag : tag.getChilds()) {   System.out.println(xmlTag.getCurrentTagName());}