PHP 5SimpleXML function Introduction to PHP SimpleXML
The SimpleXML extension provides a simple way to get the name and text of an XML element, as long as you know the layout of the XML document.
SimpleXML transforms an XML document into a SimpleXMLElement object.
This object can be processed like any other object through the normal property selector and array iterators.
tip: compared to DOM or Expat parsers, SimpleXML can read text data in an element with just a few lines of code.
Installation
The SimpleXML extension requires PHP 5 support.
Since PHP 5, the SimpleXML function is part of the PHP core. These functions can be used without installation.
PHP 5 SimpleXML functions
function |
Description |
__construct () |
Creates a new SimpleXMLElement object. |
AddAttribute () |
Adds an attribute to the SimpleXML element. |
AddChild () |
Adds a child element to a SimpleXML element. |
Asxml () |
Formats the data for the SimpleXML object in XML (version 1.0). |
Attributes () |
Returns the attributes and values of an XML tag. |
Children () |
Finds the child nodes of the specified node. |
Count () |
Calculates the number of child nodes for the specified node. |
Getdocnamespaces () |
Returns the declared namespace in the document. |
GetName () |
Returns the name of the XML tag referenced by the SimpleXML element. |
GetNamespaces () |
Returns the namespaces used in the document. |
Registerxpathnamespace () |
Creates a namespace context for the next XPath query. |
SaveXML () |
The alias of the Asxml (). |
Simplexml_import_dom () |
Returns a SimpleXMLElement object from a DOM node. |
Simplexml_load_file () |
Transforms an XML file into a SimpleXMLElement object. |
Simplexml_load_string () |
Converts an XML string to a SimpleXMLElement object. |
XPath () |
Run an XPath query on the XML data. |
PHP 5 SimpleXML iterative functions
function |
Description |
Current () |
Returns the current element. |
GetChildren () |
Returns the child elements of the current element. |
HasChildren () |
Checks whether the current element has child elements. |
Key () |
Returns the current key. |
Next () |
Move to the next element. |
Rewind () |
Rewind to the first element. |
Valid () |
Checks whether the current element is valid. |
PHP 5 SimpleXML functions