Simplify the task of creating XML documents with the XML_Serializer class, which lets you build nested XML documents from PHP data structures like arrays and objects (and vice versa). I'll show you how to build an XML document tree via the XML_Serializer class from PEAR, how to programmatically create an XML document from an array or an object, how to attach attributes to elements, and how to customize the behavior of the serializer. All this, and much, much more!
Now, what about those pesky attributes? Well, XML_Serializer comes with an option that allows you to represent array keys as attributes of the enclosing element (instead of elements themselves). Take a look:
<?php
// include class file include("Serializer.php");
// create object $serializer = new XML_Serializer();
Note that in order for this to work, the array key which is to be represented as an attribute should point to a single scalar value and not another array or object. To understand this better, consider the following example, which demonstrates the difference:
<?php
// include class file include("Serializer.php");
// create object $serializer = new XML_Serializer();