• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

difference between SAX and DOM?

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

can any one tell me the difference between sax and dom parser??

and which is best??

thanks in advance
Gopal
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A DOM parser builds a tree of nodes that represent the XML nodes, elements and attributes that comprise a document. It's convenient and intuitive to use, but memory intensive and slow.

A SAX parser is "event driven." You write a handler that is notified when the parser sees an opening or closing element, an attribute, etc. You then do whatever you want with that information. It can be hard for some people to understand, but it's fast and memory-efficient.
 
gopal kishan
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Friedman-Hill,

Thanks for your reply.

I know that SAX is a one way parser, and DOM is a two way parser. it means SAX can parse XML to java object but not from java object to XML, but DOM does two ways.

is it right?? please clarify.....


thanks in advance
Gopal
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot modify an XML document file using SAX you can only read it.
You cannot create a new XML document from scratch using SAX.

If you want to do either of these then use DOM or even better JDOM

Regards,
Rajagopal
 
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

You cannot modify an XML document file using SAX you can only read it.
You cannot create a new XML document from scratch using SAX.


Close but not exactly true -
You can use SAX to modify an input XML document if you write the modified document on the fly. Since you only get access to one element at a time, you are limited as to the types of modifications BUT there is no limit on document size the way DOM limits you to a document that fits in memory.
The Cocoon project does some amazing things with "pipelines" of SAX events.
Bill
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic