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. |