Easy Tutorial
❮ Php Imagecolordeallocate Func Xml Parse ❯

PHP 5 SimpleXML Functions


Introduction to PHP SimpleXML

The SimpleXML extension provides a simple way of getting the names and text of XML elements, as long as you know the layout of the XML document.

SimpleXML converts an XML document into a SimpleXMLElement object.

This object can be processed like any other object with normal attribute selectors and array iterators.

Tip: Compared to DOM or Expat parsers, SimpleXML takes only a few lines of code to read text data from an element.


Installation

The SimpleXML extension requires PHP 5 support.

Since PHP 5, the SimpleXML functions are part of the PHP core. No installation is required to use these functions.


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 the SimpleXML element.
asXML() Formats the data in the SimpleXML object as XML (version 1.0).
attributes() Returns the attributes and values of the XML tag.
children() Finds the children of a specified node.
count() Counts the number of children of a specified node.
getDocNamespaces() Returns the namespaces declared 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() asXML()
simplexml_import_dom() Returns a SimpleXMLElement object from a DOM node.
simplexml_load_file() Converts an XML file into a SimpleXMLElement object.
simplexml_load_string() Converts an XML string into a SimpleXMLElement object.
xpath() Runs an XPath query on XML data.

PHP 5 SimpleXML Iteration Functions

Function 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 if the current element is valid.
❮ Php Imagecolordeallocate Func Xml Parse ❯