(A Python version of this class can be found here)
XMLElegant is a PHP class that allows easy generation of XML. While SimpleXML provides a convenient way of reading XML files, I haven't seen a similar tool to help with XML generation.
As a quick example, the following XML:
<books>
<book>
<title>Title 1</title>
<author>Author 1</author>
<isbn>isbn 1</isbn>
</book>
<book>
<title>Title 2</title>
<author>Author 2</author>
<isbn>isbn 2</isbn>
</book>
<book>
<title>Title 3</title>
<author>Author 3</author>
<isbn>isbn 3</isbn>
</book>
...
</books>
can be generated by:
<?php
$x = new XMLegant();
for($i=0;$i<5;$i++)
$x->books->book()->title("Title $i")
->author("Author $i")
->isbn("isbn $i");
echo $x->toXML();
?>
The following XML: c d f g o
can be generated by either:
<?php
$x = new XMLegant();
$x->a->b = 'c';
$x->a->b[] = 'd';
$x->a->e = 'f';
$x->a->b[] = 'g';
$x->a->h->i['j'] = 'k';
$x->a->h->l->m;
$x->a->h->n = 'o';
?>
or:
<?php
$x = new XMLegant();
$x->a()
->b('c')
->b('d')
->e('f')
->b('g')
->h()
->i('j', 'k')
->l()
->m('')
->getParent()
->n('o');
?>
Many more examples are available in demo.php. Also, XMLegant_Tests.php consists of a number of unit tests that may be useful as a guide.