tags:

views:

379

answers:

7
+1  Q: 

Java API for XML

Hello,

which is a good Java API for working with XML (both DOM and SAX approaches)? Is JAXP a good choice, or is it deprecated? And, what good tutorial on the suggested API do you know?

Thanks.

+4  A: 

I like JDOM, http://jdom.org, which is especially nice to use for DOM and XPath. It bases its SAX on the JAXP classes.

Björn
That would have been my first answer too.
mkoeller
Some time ago JDOM had a weak spot on namespace handling, though. I don't know if this is still the case today.
mkoeller
+2  A: 

StaX is worth mentioning I think.

Johannes Weiß
+1  A: 

JAXP isn't deprecated. It's a good choice for low-level XML operations in Java. As always, it depends on what you're wanting to do with the XML.

If you're just converting to and from Objects, try JAXB 2.0. If you need true low level XML manipulation (low-level parsing, XSLT transformation, XPath, etc) JAXP is a good choice.

Note that many Java XML solutions, including JAXB 2.0, StaX, and Jdom (IIRC) integrate nicely with JAXP, and can easily be passed to and from JAXP processors.

Sean Reilly
+2  A: 

Also, try XOM, which is a modern alternative to JDOM.

toolkit
A: 

It ABSOLUTELY depends on what you're doing. Other people will throw in their favorite thing to work with, but this is a pointless question without clarification.

Russell Leggett
+1  A: 

I recommend you Xerces. Support for both DOM and Sax, which is a library that has been trying for years. First Look at Xerces. If not enough or if you encounter problems look at other libraries.

rayyildiz
Xerces is the implementation of JAXP that is used in the Sun JRE.
Tom Hawtin - tackline
And it's horrible really. I've recently build a project with it and there was one week when almost all I got was NPE:s in internal methods of JRE Xerces which almost cause me to change my job to farming...
Esko
+1  A: 

If you want to deal with XML,and don't need to parse it, then XMLBeans is nice. You give it a schema and it generates the classes to deal with the parsing.

TofuBeer