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