PHP asXML() Function

In this chapter you will learn:

  1. Description for PHP asXML() Function
  2. Syntax for PHP asXML() Function
  3. Parameter for PHP asXML() Function
  4. Return for PHP asXML() Function
  5. Example - Format the SimpleXML object's data in XML

Description

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//from j a  va  2s . c o  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.

Next chapter...

What you will learn in the next chapter:

  1. Description for PHP attributes() Function
  2. Syntax for PHP attributes() Function
  3. Parameter for PHP attributes() Function
  4. Return for PHP attributes() Function
  5. Example - Return attributes and values within the XML body element
Home » PHP Tutorial » PHP SimpleXML Functions
PHP SimpleXMLElement Create
PHP addAttribute() Function
PHP addChild() Function
PHP asXML() Function
PHP attributes() Function
PHP children() Function
PHP SimpleXML count() Function
PHP getDocNamespaces() Function
PHP getName() Function
PHP getNamespaces() Function
PHP registerXPathNamespace() Function
PHP simplexml_import_dom() Function
PHP simplexml_load_file() Function
PHP simplexml_load_string() Function
PHP xpath() Function