"is there a way to add a php simplexmlelement to another simplexmlelement?" Answer’s


Hey unknown. You have to use the DOMElement interface to your SimpleXML objects to achieve this.


$s = new SimpleXMLElement('<root/>');
$t = new DOMElement('child');

$dom = dom_import_simplexml($s);

echo $s->asXML();
// <root><child/></root>

If you need more specific details, let me know. There are several examples in the documentation and comments for the dom_import_simplexml() method too: http://php.net/dom_import_simplexml

Wednesday, March 31, 2021
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :