• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

JAXP with DOM parser or JDOM - Which to use?

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
John Fairbairn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See this - http://www.jdom.org/docs/apidocs/org/jdom/adapters/package-summary.html
 
John Fairbairn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic