Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

DOM or SAX

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Guys,
Well i am new to XML and i have a query related to SAX and DOM. i just wanna know which one is best to use under which circumstances and what are the advantages and disadvantages apart from memory constraints. and if i am not wrong then these are not API's, these are just the framework and API's are provided by diff vendors like SUN. Correct me if i am wrong.
Thanks in advance
Cheers
Harry
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use JDom (www.jdom.org). It's an easy to use and yet powerful DOM for Java.
Marcel
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which API do most firms use? DOM, JDOM, or SAX?
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SAX
- event driven, a bit harder to visualise.
- a lot more programming then DOM
- fastest and lease memory-intensive.
- can't back up to earlier part of document because it is serial data stream.
DOM
- tree structure with nodes.
- object base
- allow create nodes, remove nodes, change their contents, and traverse the node hierarchy.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't mean to rain the parade, but the names Maddy and Jeff c does not comply with the JavaRanch naming policy. We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please spare a moment and re-register with a name that meets these requirements.
Thanks!
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SAX is extremely lightweight and fast. It does have limitations:
It's a reader only (you cannot write XML with SAX).
It's purely sequential. No random access to your data, just take it in document order.
No context. When the SAX event for a given node fires, no information about what node it is nested in is included... you have to track that yourself if it's important to you.
DOM is more complete -- it represents your entire data structure as a tree of nodes which can be "walked" in any way that suits you. Ask a node about its parents, siblings, children, attriburtes, through method calls on the object that represents it. Much more flexible and powerful.
DOM, however, requires that the entire tree be instantiated into memory, which can be a problem for large documents. Also, it's a fairly complex set of objects you're dealing with, with its own collections, etc... Finally, it's meant to be implemented in "any" language, so it does not take advantage of things like method overloading and the like.
For Java-specific development, take a look at JDom (www.jdom.org). It's lighter-weight, uses Java collections (List), method overloading, etc... can be used creationally, and is very fast.
Brett McLaughlin, the author of the excellent "Java and XML", is one of the authors of JDom.
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scott,
How does something like Castor compare to SAX and DOM? I know the way it works is entirely different, but how come its concept isn't in wide use yet? I haven't used JDOM yet, is there something that would make it better than Castor, or JAXB for that matter? From what I've seen, Castor seems like the way to go for now...
/rick
 
Maddy Tillie
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys for the help and i will re register too
regards
Maddy tillie
 
Something about .... going for a swim. With this tiny ad ...
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic