The asXML() function formats the SimpleXML object's data in XML (version 1.0).
PHP asXML() Function has the following syntax.
asXML(filename);
Parameter | Is Required | Description |
---|---|---|
filename | Optional. | Name of the file to write the data tod |
Returns a string on success. FALSE on failure.
If the filename parameter is specified, it returns TRUE on success, FALSE on failure.
Format the SimpleXML object's data in XML:
<?php// w w w . j av a 2 s . co m
$note=<<<XML
<book>
<name>PHP</name>
<name>Java</name>
</book>
XML;
$xml=new SimpleXMLElement($note);
echo $xml->asXML();
?>
The code above generates the following result.