WebReference.com - Part 4 of Chapter 10 from Professional PHP4 XML, from Wrox Press Ltd (5/5)
Professional PHP4 XML, Chapter 10: Putting It Together
In most cases, the DOM approach uses more resources and is the slowest one too. DOM is a good solution to modify and write small- to medium-sized documents from non-XML data. DOM is not recommended for querying and transforming documents.
XSLT is the most interesting solution for modifying, transforming, or querying documents, unless the documents are so big that XSLT can't process them and we have to use SAX instead. Our XSLT stylesheets can perform complex queries or transformations with just a few lines of XSLT code, so if the size of the documents allows us to use XSLT, then it should surely be one of our primary weapons.
SAX is the only solution for processing really large files and it is also a good solution for a fast implementation of other processing problems. SAX filters and filter chains are the tools we should be constructing when SAX is our selected tool for a problem.
XPath, as we've seen in this chapter and in Chapter 7, is a good solution for not very complex queries since it requires just an XPath expression and a few lines of code. Since the XPath implementation of PHP is part of the DOM extension, it is not recommended for big files. SAX-based XPath implementations can be used to query large documents.
In this chapter we have seen examples that provide a good base, examples that use DOM, SAX, and XSLT for XML processing, and seen how to use these standards from PHP. After reading and practicing these examples we'll be able to select the best approach to a given problem and that's a key skill for any programmer dealing with XML data in the enormous ocean of derivatives available.
Created: September 3, 2002
Revised: September 3, 2002