- dom_import_simplexml: documentation ( source)
<?php
$xml = new SimpleXMLElement('<xml xmlns="http://xml" xmlns:foo="http://foo" xmlns:bar="http://bar" />');
$foo = $xml->addChild('foo', null, 'http://foo');
$tag = $foo->addChild('bar', null, 'http://bar');
$foo->bar[0] = 'Hello World!';
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
echo $dom->saveXML();