I\'m trying to build a rather complex XML document.
I have a bunch of sections of the XML document that repeats. I thought I\'d use multiple string templates as base
You could use this function that is based in creating the children with attributes from the source:
function xml_adopt($root, $new) {
$node = $root->addChild($new->getName(), (string) $new);
foreach($new->attributes() as $attr => $value) {
$node->addAttribute($attr, $value);
}
foreach($new->children() as $ch) {
xml_adopt($node, $ch);
}
}
$xml = new SimpleXMLElement(" ");
$child = new SimpleXMLElement("a paragraph
another
p
");
xml_adopt($xml, $child);
echo $xml->asXML()."\n";
This will produce:
a paragraph
another p