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
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.
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!
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
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@example.com<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
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
Joined: Jan 10, 2002
Thanks guys for the help and i will re register too regards Maddy tillie