As mentioned earlier, dom_import_simplexml () will return a DOMElement from which you can get the associated DOMDocument:
$doc = dom_import_simplexml($my_simplexml)->ownerDocument;
If you do not plan to use SimpleXML, you can load the document directly from the DOM.
$doc = new DOMDocument; $doc->load($url);
source share