SAX or DOM?

printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    

Java APIs for XML Kick Start
By Aoyon Chowdhury, Parag Choudhary

Table of Contents
Chapter 6.  XSLT and XPath


You just saw two examples of transformations, one with the SAX and the other with the DOM. Which one should you use? The answer, like all other things in life, is it depends!

As you saw in earlier chapters, SAX is a serial processing parser and does not create an in-memory representation of the XML data. So, the information about the element is lost as soon as the parser reaches the next element. Although this makes it fast and light on resources, there is no way to determine where exactly you are in the document hierarchy, or the relationship between the elements.

In contrast, DOM creates an in-memory representation of the XML data. Although this feature makes it possible for an application to randomly access and modify the XML data any number of times, it also means that for large or complex XML documents, resource utilization can become a significant issue.

If you are creating an XSLT stylesheet in which you apply templates depending on the element relationships, you are definitely better off with DOM. If that isn't the case, SAX is a better choice. But at the end of the day, as a programmer, you must make the call whether to pick up SAX- or DOM-based XSLT transforms.


printer-friendly version of this section  Print  e-mail this section  E-Mail  add a public, group or private note  Add Note  add a bookmark about this section  Add Bookmark    
Top

[0672324342/ch06lev1sec5]

 
 


JavaT APIs for XML Kick Start
JAX: Java APIs for XML Kick Start
ISBN: 0672324342
EAN: 2147483647
Year: 2002
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net