PHP SimpleXML function usage analysis, phpsimplexml_PHP tutorial-php Tutorial

Source: Internet
Author: User
PHP SimpleXML function usage analysis, phpsimplexml. PHP SimpleXML function usage analysis. phpsimplexml this article describes the usage of SimpleXML function in php. This function allows you to convert XML into an object, I will share with you the usage analysis of SimpleXML functions in PHP, phpsimplexml

This example describes how to use SimpleXML in php. This function allows you to convert XML into an object and share it with you for your reference. The specific analysis is as follows:

The SimpleXML function allows you to convert XML into an object. you can process this object by using a common attribute selector or an array iterator, just like processing any other object. some of these functions require the latest PHP version.

Installation: SimpleXML functions are part of the PHP core and can be used without installation. the code is as follows:

The code is as follows:

<? Php
// Return all content as an object
$ Lib = simplexml_load_file ("cet4.xml ");
// Return the obtained item node in array form
$ Items = $ lib-> item;
$ WordsLength = sqlserver/42852.htm target = _ blank> count ($ items );
// Obtain the node values of all nodes
For ($ I = 0; $ I <$ wordsLength; $ I ++ ){
$ Word = $ items [$ I];
Echo $ word-> word. '-----'. $ word-> trans. '-----'. $ word-> phonetic .'
';
}
// Combination of simplexml and xpath is omnipotent
$ Words = $ lib-> xpath ("// word ");
// Method for obtaining attributes
Echo $ words [0] ['add'].'
';
Echo $ items [0] ['pp '];
?>


Related functions are described as follows:

Function Description PHP version
_ Construct () Create a new SimpleXMLElement object 5
AddAttribute () Add an attribute to the SimpleXML element 5
AddChild () Add a child element to the SimpleXML element 5
AsXML () Obtain an XML string from the SimpleXML element 5
Attributes () Get SimpleXML element attributes 5
Children () Obtains the subnode of a specified node. 5
GetDocNamespaces () Get the namespace of the XML document 5
GetName () Get SimpleXML element name 5
GetNamespaces () Get namespace from XML data 5
RegisterXPathNamespace () Create a namespace context for the next XPath query 5
Simplexml_import_dom () Get SimpleXMLElement object from DOM node 5
Simplexml_load_file () Get SimpleXMLElement object from XML document 5
Simplexml_load_string () Get SimpleXMLElement object from XML string 5
Xpath () Run XPath query on XML data 5

I hope this article will help you with PHP programming.

Examples in this article describes how to use SimpleXML functions in php. This function allows you to convert XML into objects and share it with you for your reference...

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.