I've read that it is easier to parse XML documents using the JDOM API rather than using JAXP with the DOM parser. But, maybe JAXP is recognized as more of an industry standard than JDOM because it is Sun's Java API for XML parsing and should be used for that reason. The parsing I'll be doing could be complex... Any opinions are appreciated... Thanks, John
Comparing JAXP with JDOM is like comparing apples and oranges. They don't quite have any comparable features since they address totally different problem domains. JAXP allows you to "plug-in" your choice of parsers without affecting the client code. It abstracts an underlying parser( DOM and SAX ) through a standard set of API. JAXP uses by default Sun's Crimson parser, but you can use any JAXP compliant parsers. In fact, you can write your own JAXP wrapper if the parsers is non-compliant. So JAXP is a pre-parsing solution. JDOM helps you use standard Java2 Collection classes to manipulate a DOM tree once the document is parsed. It simply wraps the W3C DOM data structures into standard collections and simplifies document handling logic. We assume here that the document has already been parsed. So JDOM is a post-parsing solution. As you can see, they are not mutually exclusive. You can use both JAXP and JDOM in your solution; or you can only use JDOM if you don't envision parser-switching; or you can only use JAXP if you are comfortable with DOM datastructures and don't need an additional mapping layer; you may not use either of them and simply call standard DOM parser dirctly from the client code. Hope you get the point.. BTW JDOM is a JSR now and will be incorporated into Sun's standard XML support soon.
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ajith... thanks for your detailed explanation. So... JAXP provides an abstraction layer over the vendor specific parser being used. The DOM or SAX parser would have to implement the JAXP abstract classes. JDOM manipulates a DOM document directly once the document is parsed. One thing that I don't get. You mentioned:
As you can see, they are not mutually exclusive. You can use both JAXP and JDOM in your solution;
If I was to use JAXP to obtain a DOM parser, I could then use the standard DOM objects and methods to manipulate the document. With JDOM, I'd create a org.jdom.Document and manipulate that Document object. In what situation would I want to use both JAXP and JDOM together? Please excuse my ignorance as I'm new to XML parsing in Java. Thanks, John
So JDOM also supplies a library of adapters (including a JAXPDOMAdapter) which can be used to return an org.w3c.dom.Document object. If I was going to use JDOM, why would I use the org.w3c.dom.Document object over the org.jdom.Document object which seems easier to use? I guess because the JAXPDOMAdapter provides a level of abstraction over the vendor specific parser being used... is this the value of using this class? Just trying to get a crystal clear picture of how JAXP and JDOM can be best used. Thanks for your patience. John
Many people seem to feel that JDOM gives you an API thats closer in feel to Java practice. If you create a jdom.Document naturally you will use JDOM method, but somewhere in the background there will be a JAXP parser. If you need to handle a document in the SAX fashion JDOM has nothing to offer you. My suggestion is that you should download Sun's current XML Pack from java.sun.com and experiment with the examples. Bill