Need to manipulate XML document trees, but don't have the DOM extension compiled into your PHP build? Take a look at XMLTree, a PEAR class that allows you to create and manipulate XML document trees without requiring the PHP DOM extension.
The XMLTree class comes courtesy of PEAR, the PHP Extension and Application Repository (http://pear.php.net). In case you didn't know, PEAR is an online repository of free PHP software, including classes and modules for everything from data archiving to XML parsing. When you install PHP, a whole bunch of PEAR modules get installed as well; the XMLTree class is one of them.
In case your PHP distribution didn't include XMLTree, you can get yourself a copy from the official PEAR Web site, at http://pear.php.net - simply unzip the distribution archive into your PEAR directory and you're ready to roll!
Let's begin with something simple - dynamically constructing an XML document using XMLTree methods. Here's the code:
// include class
// instantiate object
= new XML_Tree();
// add the root element
$root =& $tree->addRoot("superhero");
add child elements
$name =& $root->addChild("name", "Peter Parker aka Spiderman");
// print tree
Don't worry if it didn't make too much sense - all will be explained shortly. For the moment, just feast your eyes on the output: