Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which one to use?

 
T Bush
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK people. I'm looking to add XML capabilities to my company's product but one question remains: Which parser should be use? I've hear (seen) people praise JDom over JAXP but never explain why. So I'm asking, the great people of the java ranch world, which parser is the best and why?
Thank to all of you.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAXP is a management interface which allows you to "plug in" various DOM or SAX parser implementations. JDOM is a "native Java" document model which wraps round a DOM or SAX parser.
If you are writing Java code to create, edit, manipulate XML data, and have no particular requirement for DOM-compatibility at the object and method level, then JDOM is much easier to use than raw DOM. You can still use JAXP to control which parser you choose, or you can tie yourself to a particular parser.
 
T Bush
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info. How about performance? Since JDOM ties itself to a particular parser is it any faster? And would the speed be equal if I used the Xerces parser with JAXP?
Thanks again
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDOM doesn't constrain the choice of parsers - you can use any parser you want. However since JDOM is built over DOM, your parsing shouldn't be SAX-based method.
SAX parsers are always lightweight since they are event-based. DOM parsers offer flexibility of random access, traversal and easy mutators of the XML data, but they consume significant memory since they represent the whole document as an in-memory tree.
Having said that, for small XML documents you will really not see a big difference between SAX and DOM. The performance issues become significant only when you're dealing with relatively large documents.
Hope that helps,
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
T Bush
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I'm giving up flexability with JDOM. If I'm looking for a parser to do a wide range of jobs (SAX and DOM), JAXP is my best bet?
 
hanumanth reddy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U can do both Dom and sax Using JDom and is the best ad simply to use api
Hanumanth reddy
 
T Bush
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So ease of use is the only reason to go with JDOM? JAXP also provides hooks to use Xalan for transforming. Does JDOM do anything like that? Since Sun is also developing JAXM, XML/Java Binding, and serialization to XML would JAXP be the better choice?
Thanks again
 
mars76
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

JDOM is one of the best XML Parsers if not the best..I have used many diffrent parsers like ( Xerces , dom4j ) etc but JDOM is so simple and easy..

regards
Sateesh
[ March 18, 2008: Message edited by: mars76 ]
 
Daniel Olson
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDOM Beta 6 which came out February 15, 2001 supports JAXP.
 
Hema Menon
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Somewhere I had found an article on how to choose your xml parsers. The article did not cover JDOM. Hopefully by tommorrow I'll be able to post the link.
-hm
 
Hema Menon
Ranch Hand
Posts: 569
 
Hema Menon
Ranch Hand
Posts: 569
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic