File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes DOM API vs SAX API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "DOM API vs SAX API" Watch "DOM API vs SAX API" New topic


Naina Si
Ranch Hand

Joined: Nov 05, 2003
Posts: 134
Where do you use these API's in real world scenarios, i know the difference between them theoretically just by reading books.

Any experienced guys out there shed some light?
Theodore Casser
Ranch Hand

Joined: Mar 14, 2001
Posts: 1902

Just depends on what you're trying to accomplish when you're parsing the XML (ie, are you searching it for specific nodes, or building something based on a single pass through the whole tree). You tailor your application to use one or the other given the requirements and resources.

DOM recreates the tree in memory and forces you to walk through it, step by step, to find what you want. SAX lets you look for specific nodes as you wander, but does it all in one pass. So that's usually the guide for determining, in the real world, which one to use.

Hope it helps.

Theodore Jonathan Casser
SCJP/SCSNI/SCBCD/SCWCD/SCDJWS/SCMAD/SCEA/MCTS/MCPD... and so many more letters than you can shake a stick at!
I agree. Here's the link:
subject: DOM API vs SAX API
It's not a secret anymore!