posted 23 years ago
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.
Scott Bain<br />Senior Consultant<br />Net Objectives<br />425-591-5844<br /><a href="http://www.netobjectives.com" target="_blank" rel="nofollow">Net Objectives</a><br />----------------------------<br />* Sign up for our free newsletter by sending an e-mail to<br />[email protected]<br />* Learn about and join our design pattern community of practice by going to<br /><a href="http://www.netobjectives.com/dpexplained" target="_blank" rel="nofollow">www.netobjectives.com/dpexplained</a><br />* Alan Shalloway & Jim Trott's - Design Patterns Explained: A New Perspective on<br />Object-Oriented Design is now available<br />* Our new CDROM-based XML training is now available as well