The "addChild" method of SimpleXMLElement seems like it should be the right choice, but it apparently only takes strings representing the tagname of the new child.
There's the object-ish notation for referencing nodes of the tree and setting them, e.g. $simpleXMLNode->child = value, but that only seems to work for simple text/numeric values. If I try the following:
$s = new SimpleXMLElement('<root/>');
$t = new SimpleXMLElement('<child/>');
$s->a = $t;
echo $s->asXML()
I get:
<?xml version="1.0"?>
<root><a></a></root>
when I was hoping for:
<?xml version="1.0"?>
<root><a><child/></a></root>
I thought of converting $t to a string and then adding it (after stripping out the XML declaration):
$s->a = substr($t->asXML(),22)
But this yields:
<?xml version="1.0"?>
<root><a><child/></a></root>
Again, not what I was hoping for.
Is there a typical way to accomplish this kind of thing with SimpleXML?