5

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.)

hakre
  • 193,403
  • 52
  • 435
  • 836
bobbiloo
  • 422
  • 5
  • 22

2 Answers2

5

$sxml is a simpleXMLElement

$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->loadXML($sxml->asXML());
$xml = $doc->saveXML();
None
  • 5,491
  • 1
  • 40
  • 51
2

If you have a SimpleXMLElement object, you can use the asXML method to get an XML string: http://us2.php.net/manual/en/simplexmlelement.asxml.php

Scott Saunders
  • 29,840
  • 14
  • 57
  • 64