Skip to main content

The simple XML Extension

 

PHP SimpleXML Introduction

SimpleXML is an extension that allows us to easily manipulate and get XML data.

SimpleXML provides an easy way of getting an element's name, attributes and textual content if you know the XML document's structure or layout.

SimpleXML turns an XML document into a data structure you can iterate through like a collection of arrays and objects.


FunctionDescription
__construct()Creates a new SimpleXMLElement object
__toString()Returns the string content of an element
addAttribute()Appends an attribute to the SimpleXML element
addChild()Appends a child element the SimpleXML element
asXML()Returns a well-formed XML string (XML version 1.0) from a SimpleXML object
attributes()Returns the attributes/values of an element
children()Returns the children of a specified node
count()Counts the children of a specified node
getDocNamespaces()Returns the namespaces declared in document
getName()Returns the name of an element
getNamespaces()Returns the namespaces used in document
registerXPathNamespace()Creates a namespace context for the next XPath query
saveXML()Alias of asXML()
simplexml_import_dom()Returns a SimpleXMLElement object from a DOM node
simplexml_load_file()Converts an XML document to an object
simplexml_load_string()Converts an XML string to an object
xpath()Runs an XPath query on XML data

Comments