Introduction to SimpleXML Functions in PHP _php tutorial

Source: Internet
Author: User
Tags xpath
This article simply introduces the use of the SimpleXML function in PHP, which allows you to convert XML to an object that you need to know.

The SimpleXML function allows you to convert XML to an object.

This object can be handled by a normal property selector or an array iterator, just as it does with any other object.

Some of these functions require the latest version of PHP.
Installation
The SimpleXML function is part of the PHP core. These functions can be used without installation.

TD bgcolor= "#FFE7CE" height= "width=" 464 "> code as follows
copy code
//Return all content as Object
$lib = Simplexml_load _file ("Cet4.xml");
//Returns the retrieved item node as an array
$items = $lib->item;
$wordsLength = sqlserver/42852.htm Target=_blank >count ($ Items);
//Gets the node value under all nodes
for ($i =0; $i < $wordsLength; $i + +) {
$word = $items [$i];
Echo $word->word. '-----'. $ Word->trans. '-----' $word->phonetic. '
';
}
//simplexml with XPath does not have
$words = $lib->xpath ("//word");
//method to get Properties
Echo $words [0][' Add ']. '
';
Echo $items [0][' PP '];
?

Related functions

PHP: Indicates the earliest version of PHP that supports this function.

Function Description PHP
__construct () Creates a new SimpleXMLElement object. 5
AddAttribute () Adds an attribute to the SimpleXML element. 5
AddChild () adds a child element to the SimpleXML element. 5
Asxml () Gets the XML string from the SimpleXML element. 5
Attributes () Gets the properties of the SimpleXML element. 5
Children () Gets the child of the specified node. 5
Getdocnamespaces () Gets the namespace of the XML document. 5
GetName () Gets the name of the SimpleXML element. 5
GetNamespaces () Gets the namespace from the XML data. 5
Registerxpathnamespace () Creates a namespace context for the next XPath query. 5
Simplexml_import_dom () Gets the SimpleXMLElement object from the DOM node. 5
Simplexml_load_file () Gets the SimpleXMLElement object from the XML document. 5
Simplexml_load_string () Gets the SimpleXMLElement object from an XML string. 5
XPath () runs an XPath query against the XML data. 5


http://www.bkjia.com/PHPjc/445310.html www.bkjia.com true http://www.bkjia.com/PHPjc/445310.html techarticle This article simply introduces the use of the SimpleXML function in PHP, which allows you to convert XML to an object that you need to know. The SimpleXML function allows you to put ...

  • 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.