How to convert a stdClass object to a SimpleXMLElement object
Using the XML Serializer package, you can use the following code to make the conversion, as reported in this answer on Stack Overflow.

function json_to_xml($json) {
  $serializer = new XML_Serializer();
  $obj = json_decode($json);

  if ($serializer-&gt;serialize($obj)) {
    return $serializer-&gt;getSerializedData();
  }
  else {
    return NULL;
  }
}


Alternatively, you can use the following code give in this answer for the same question.

require_once 'XML/Serializer.php';

$data = json_decode($json, true)

// An array of serializer options.
$serializer_options = array (
  'addDecl' =&gt; TRUE,
  'encoding' =&gt; 'ISO-8859-1',
  'indent' =&gt; '  ',
  'rootName' =&gt; 'json',
  'mode' =&gt; 'simplexml'
); 

$Serializer = &amp;new XML_Serializer($serializer_options);
$status = $Serializer-&gt;serialize($data);

if (PEAR::isError($status)) {
  die($status-&gt;getMessage());
}

echo '&lt;pre&gt;';
echo htmlspecialchars($Serializer-&gt;getSerializedData());
echo '&lt;/pre&gt;';