I'm trying to create a simple wrapper function for outputting my errors in XML for an existing Flash application. I've already read that SimpleXMLElement
is not necessarily intended for creating a new XML document but it's working fine for me so far and I am basically replacing concatenated strings.
Up until now I've had no problems iterating and adding/modifying attribues, values, etc. In this example I would like to see my output look like this:
<ERROR>There is an error</ERROR>
But I am seeing this:
<ERROR>
<ERROR>There is an error</ERROR>
</ERROR>
Here's the code:
$msg = 'There is an error';
$xmlstr = "<ERROR></ERROR>";
$sxml = new SimpleXMLElement($xmlstr);
$sxmlErr = $sxml->ERROR = $msg;
echo $sxml->asXML();
It seems that using the $obj->node
syntax creates a child node. And the only way I can instantiate a SimpleXMLElement
is by passing the parent node.