PHP Tutorial - PHP asXML() Function






The asXML() function formats the SimpleXML object's data in XML (version 1.0).

Syntax

PHP asXML() Function has the following syntax.

asXML(filename);

Parameter

ParameterIs RequiredDescription
filenameOptional.Name of the file to write the data tod

Return

Returns a string on success. FALSE on failure.

If the filename parameter is specified, it returns TRUE on success, FALSE on failure.

Example

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.