I'd like to build an object-oriented toolkit for PHP to make creating and/or parsing XML much simpler, but before I spend any time seriously developing it, I wanted to see if someone else has already built a better wheel for the same purpose.
I'd envision something where a class would represent a opening and closing pair of tags, and providing an xml string would return a hierarchy of objects:
// a simplified example, but this would represent '<order id="A1">Lorem ipsum</order>'
class XmlClass {
$name = 'order';
$content = 'Lorem ipsum';
$attributes = array('id' => 'A1');
$children = array(); // this would child tag objects of this same class
}
Using this kind of interface, you could even provide an entire xml document as the string, and get back a hierarchical structure of class objects.
Additionally, you could directly instantiate a new class, and the use a method of the same class to output the equivalent xml:
// this would (more or less) output '<order id="C6">The quick fox jumps over the lazy dog</order>'
$tag = new XmlClass( 'order', 'The quick fox jumps over the lazy dog', array('id' => 'C6') );
echo $tag->to_string();
What this would accomplish (in theory) is something easy to use like SimpleXML, but potentially much more powerful in the long run. It would allow parsing and manipulation of a single snippet or an entire document, as well as making programmatic xml generation a breeze.
Thoughts? Admonishments, praises, reprimands?