Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

PHP 5 SimpleXML function


May 11, 2021 PHP


Table of contents


PHP 5 SimpleXML function


Introduction to PHP SimpleXML

The SimpleXML extension provides an easy way to get the name and text of an XML element, as long as you know the layout of the XML document.

SimpleXML transforms XML documents to SimpleXMLElement objects.

With normal property selectors and array iterators, this object can be processed like any other object.

Tip: SimpleXML requires only a few lines of code to read text data in an element compared to a DOM or Expat parser.


Installation

SimpleXML extensions require PHP 5 support.

Since PHP 5, SimpleXML functions have been part of the PHP core. These functions can be used without installation.


PHP 5 SimpleXML function

function describe
__construct() Create a new SimpleXmleleMefficient object.
addAttribute() Add an attribute to the Simplexml element.
addChild() Add a child element to the Simplexml element.
asXML() Format the data of SimpleXML objects in XML (Version 1.0).
attributes() Returns the properties and values of the XML tag.
children() Find the child node of the specified node.
count() Calculate the number of child nodes of the specified node.
getDocNamespaces() Returns the namespace of the declaration in the document.
getName() Returns the name of the XML tag referenced by Simplexml element.
getNamespaces() Returns the namespace used in the document.
registerXPathNamespace() Create a namespace context for the next XPath query.
saveXML() asXML() Alias.
simplexml_import_dom() Returns the SimpleXMleleMent object from the DOM node.
simplexml_load_file() Convert XML files for SimpleXMlelement objects.
simplexml_load_string() Convert XML strings to SimplexMlelement objects.
xpath() Run the XPath query for XML data.

PHP 5 SimpleXML iterative function

function describe
current() Returns the current element.
getChildren() Returns the child elements of the current element.
hasChildren() Check if the current element has a child.
key() Returns the current key.
next() Move to the next element.
rewind() Returned to the first element.
valid() Check if the current element is valid.

Read about it

PHP XML SimpleXML