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
  • 184,866
  • 48
  • 414
  • 792
bobbiloo
  • 404
  • 5
  • 22

2 Answers2

4

$sxml is a simpleXMLElement

$doc = new DOMDocument();
$doc->formatOutput = TRUE;
$doc->loadXML($sxml->asXML());
$xml = $doc->saveXML();
None
  • 5,291
  • 1
  • 38
  • 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
  • 28,922
  • 14
  • 55
  • 63