O'Reilly logo

Upgrading to PHP 5 by Adam Trachtenberg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

DOM

DOM is one of PHP 5’s two major XML processing extensions. This section introduces DOM, providing an overview of how it organizes information. It also demonstrates how to turn XML documents into DOM objects and vice versa.

About DOM

There is only one way to read XML into a tree using PHP 4: DOM. DOM, short for Document Object Model, is a W3C standard describing a platform- and language-neutral interface for interacting with XML and other structured documents. DOM then provides a series of utility functions to recurse through the branches and pick out the nodes and data that you want.

It’s easier to parse XML into a tree than to use a streaming parser such as SAX. When you read XML into a tree, you can move through the document in a way that is similar to navigating PHP data structures such as multi-dimensional arrays or objects that have subobjects. However, if your document is large, DOM can use lot of memory.

PHP 5’s DOM utilities have undergone a complete rewrite. If you used the DOM functions in PHP 4, you know that PHP’s DOM support has largely been sketchy and incomplete. The original implementation did not conform at all to the W3C naming conventions, thus partially defeating the purpose of a language-neutral API. Although PHP 4.3 unveiled an improved and more compliant set of DOM functions, there are still holes and memory leaks.

On top (or perhaps because) of all this, a large “EXPERIMENTAL” tag had seemingly been permanently placed upon PHP 4’s DOM functions. When the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required