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

Chapter 5. XML

PHP 5 has a completely new set of XML extensions that address major problems in PHP 4’s XML extensions. While PHP 4 allows you to manipulate XML, its XML tools are only superficially related. Each tool covers one part of the XML experience, but they weren’t designed to work together, and PHP 4 support for the more advanced XML features is often patchy. Not so in PHP 5. The new XML extensions:

  • Work together as a unified whole

  • Are standardized on a single XML library: libxml2

  • Fully comply with W3 specifications

  • Efficiently process data

  • Provide you with the right XML tool for your job

Additionally, following the PHP tenet that creating web applications should be easy, there’s a new XML extension that makes it simple to read and alter XML documents. The aptly named SimpleXML extension allows you to interact with the information in an XML document as though these pieces of information are arrays and objects, iterating through them with foreach loops and editing them in place merely by assigning new values to variables.

XML Extensions in PHP 5

PHP 5 has five major XML extensions. Each one has different features, advantages, and costs:

DOM

The 800-pound gorilla of XML. You can do everything and the <kitchen-sink> with DOM, but navigating through your documents can be cumbersome.

SAX

PHP’s original XML extension. SAX is a streaming, or event-based, parser that uses less memory than DOM, but frequently requires more complex PHP code.

SimpleXML

A new PHP 5-only extension that excels ...

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