SimpleXMLElement Object back to XML

php, simplexml, xml

Solution

$sxml is a simpleXMLElement

$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->loadXML($sxml->asXML());
$xml = $doc->saveXML();

Problem

Let's say you're getting the following response from an API call: ``` [OrderArray] => SimpleXMLElement Object ( [Order] => Array ( [0] => SimpleXMLElement Object ( [OrderID] => etc...etc..<br> ``` How do I go about converting this back into well-formatted XML so that I can save each of my order arrays into their own separate file? (Please don't ask me why I have to perform this seemingly futile task.)

Original source

Related problems