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>Do not 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
SimpleXMLElement::asXML(filename)
Parameter Values
Parameter | Description |
---|---|
filename | Optional. If specified, the data is written to the file, instead of returning a string |
Technical Details
Return Value: | A string (or TRUE if the filename parameter is set) on success. FALSE on failure |
---|---|
PHP Version: | 5.0+ |
❮ PHP SimpleXML Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.