PHP asXML() Function
Example
Return a well-formed XML string (XML version 1.0) from a SimpleXML object:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml = new SimpleXMLElement($note);
echo $xml->asXML();
?>
Run example »
Definition and Usage
The asXML() function returns a well-formed XML string (XML version 1.0) from a SimpleXML object.
Syntax
asXML(filename);
Parameter | Description |
---|---|
filename | Optional. If specified, the function writes the data to the file, instead of returning the string |
Technical Details
Return Value: | Returns a string on success. FALSE on failure. If the filename parameter is specified, it returns TRUE on success, FALSE on failure |
---|---|
PHP Version: | 5.0.1+ |
PHP SimpleXML Reference