views:

586

answers:

6

I need to apply some xml templates to various streams of xml data (and files, on occasion) and there seem to be a large number of xml libraries for java out there -- enough that it's difficult to quickly determine which libraries are still active, how they differ from the other options that are also active, and what criteria should be considered when choosing one.

What libraries do you use for manipulating xml in java, and why is it better than the alternatives?

+2  A: 

You should decide if you want/are able to load the whole document into memory. If it is a large document, you may want to look at the sax parser. This works well for large documents. Otherwise you may want to look into a dom parser.

Milhous
+6  A: 

saxon is the xslt and xquery parser -- http://saxon.sourceforge.net/. this is built by a known xslt expert(who was on the xslt spec committe and who has authored books). there is an open source version and a commercial version.

It(xslt piece) gets continuously improved .
the other xslt tool in java, is of course, XALAN.

xml -- there are so many. notable(well tested over the years) ones
1) jdk xml parser -- dom, sax, stax
2) xerces : from apache
3) XOM -- if DOM doesn't work for you
4) JDOM -- one of the earlier popular open source tool
5) JAXB -- built into the JDK 6 now
6) woodstox -- nice xml processor(read/write) -- http://woodstox.codehaus.org/

anjanb
A: 

I use Xerces for XML parsing (DOM) and validation against XSD.

For XSLT processing I used Xalan but it was 3 years ago so many things must have change, in my memory it was easy to use and powerful (I was using input XML file of several Mo)

Vinze
+2  A: 

No one has mentioned JAXP, the Java API for XML Processing. Comes right out of the box with the jdk, with default xml library implementations.

+1  A: 

Wrt "JAXP": that's just a very simple wrapper for creating DOM or SAX parser instances. And implementation that JDK bundles is Xerces. So it's not an alternative per se; it's just the standard API to construct "JDK parser" mentioned earlier. For XSLT, Saxon is strictly superior to Xalan; featurewise, speedwise (2x). JAXB v2 good for data binding, Stax (Woodstox) best for streaming.

A: 

I've been using StAX pull parser for implementing custom memory and performance efficient POJO-2-xml serialization solution and was pretty delighted with results. It is bundled in JDK6 so you won't need any additional dependencies to run it.

nixau