SimpleXML is an 'Object Mapping XML API'. It is not DOM, per se. SimpleXML converts the XML elements into PHP's native data types.
The dom_import_simplexml and simplexml_import_dom functions do *not* create separate copies of the original object. You are free to use the methods of either or both interchangeably, since the underlying instance is the same.
<?php
$sxe = simplexml_load_string('<root/>');
$dom = dom_import_simplexml($sxe);
$element = $dom->appendChild(new DOMElement('dom_element'));
$element->setAttribute('creator', 'dom');
$sxe->dom_element['sxe_attribute'] = 'added by simplexml';
$element = $sxe->addChild('sxe_element');
$element['creator'] = 'simplexml';
$element = $dom->getElementsByTagName('sxe_element')->item(0);
$element->setAttribute('dom_attribute', 'added by dom');
echo ('<pre>');
print_r($sxe);
echo ('</pre>');
?>
Outputs:
SimpleXMLElement Object
(
[dom_element] => SimpleXMLElement Object
(
[@attributes] => Array
(
[creator] => dom
[sxe_attribute] => added by simplexml
)
)
[sxe_element] => SimpleXMLElement Object
(
[@attributes] => Array
(
[creator] => simplexml
[dom_attribute] => added by dom
)
)
)
What this illustrates is that both interfaces are operating on the same underlying object instance. Also, when you dom_import_simplexml, you can create and add new elements without reference to an ownerDocument (or documentElement).
So passing a SimpleXMLElement to another method does not mean the recipient is limited to using SimpleXML methods.
Hey Presto! Your telescope has become a pair of binoculars!