PHP 5 SimpleXMLFunctions
PHP SimpleXML Introduction
The SimpleXML extension provides a simple way to get the names and text of XML elements, as long as you know the layout of the XML document.
SimpleXML converts XML documents to SimpleXMLElement objects.
Through normal property selectors and array iterators, this object can be handled like any other object.
Tip:Compared with DOM or Expat parsers, SimpleXML only needs a few lines of code to read text data in elements.
Installation
The SimpleXML extension requires PHP 5 support.
Since PHP 5, SimpleXML functions are part of the PHP core. These functions can be used without installation.
PHP 5 SimpleXML Functions
| Functions | Description |
|---|---|
| __construct() | Creates a new SimpleXMLElement object. |
| addAttribute() | Adds an attribute to a SimpleXML element. |
| addChild() | Adds a child element to a SimpleXML element. |
| asXML() | Formats the data of a SimpleXML object in XML (version 1.0). |
| attributes() | Returns the attributes and values of XML tags. |
| children() | Finds child nodes of a specified node. |
| count() | Counts the number of child nodes of a specified node. |
| getDocNamespaces() | Returns declared namespaces in the document. |
| getName() | Returns the name of the XML tag referenced by a SimpleXML element. |
| getNamespaces() | Returns namespaces used in the document. |
| registerXPathNamespace() | Creates namespace context for the next XPath query. |
| saveXML() | asXML()Alias of. |
| simplexml_import_dom() | Returns a SimpleXMLElement object from a DOM node. |
| simplexml_load_file() | Converts an XML file to a SimpleXMLElement object. |
| simplexml_load_string() | Converts an XML string to a SimpleXMLElement object. |
| xpath() | Runs an XPath query on XML data. |
PHP 5 SimpleXML Iteration Functions
| Functions | Description |
|---|---|
| current() | Returns the current element. |
| getChildren() | Returns the children of the current element. |
| hasChildren() | Checks whether the current element has children. |
| key() | Returns the current key. |
| next() | Moves to the next element. |
| rewind() | Rewinds to the first element. |
| valid() | Checks whether the current element is valid. |