PHP 5 SimpleXML functions

Source: Internet
Author: User
Tags rewind xpath

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.