simplexml function usage Analysis in PHP, Phpsimplexml
This example describes the use of the SimpleXML function in PHP, which allows you to convert XML to an object and share it with everyone for your reference. The specific analysis is as follows:
The SimpleXML function allows you to convert XML to an object, which can be handled by an ordinary property selector or an array iterator, just like any other object. Some of these functions require the latest version of PHP.
Installation: The SimpleXML function is part of the PHP core and can be used without installation, with the following code:
Copy the Code code as follows: <?php
Return all content as an 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 value of the node under all nodes
for ($i =0; $i < $wordsLength; $i + +) {
$word = $items [$i];
echo $word->word '-----'. $word->trans. '-----'. $word->phonetic. '
';
}
SimpleXML combined with XPath is omnipotent
$words = $lib->xpath ("//word");
Methods to get Properties
echo $words [0][' Add ']. '
';
echo $items [0][' PP '];
?>
The related functions are described as follows:
Function |
Describe |
PHP version |
__construct () |
To create a new SimpleXMLElement object |
5 |
AddAttribute () |
Add a property to the SimpleXML element |
5 |
AddChild () |
Add a child element to a SimpleXML element |
5 |
Asxml () |
Getting an XML string from an SimpleXML element |
5 |
Attributes () |
Gets the properties of the SimpleXML element |
5 |
Children () |
Gets the child nodes of the specified node |
5 |
Getdocnamespaces () |
Get the namespace of an XML document |
5 |
GetName () |
Gets the name of the SimpleXML element |
5 |
GetNamespaces () |
Getting namespaces from XML data |
5 |
Registerxpathnamespace () |
Create a namespace context for the next XPath query |
5 |
Simplexml_import_dom () |
Get the SimpleXMLElement object from the DOM node |
5 |
Simplexml_load_file () |
Getting SimpleXMLElement objects from an XML document |
5 |
Simplexml_load_string () |
Get the SimpleXMLElement object from an XML string |
5 |
XPath () |
Run an XPath query on XML data |
5 |
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/917682.html www.bkjia.com true http://www.bkjia.com/PHPjc/917682.html techarticle simplexml function Usage Analysis in PHP, Phpsimplexml This example describes the use of SimpleXML functions in PHP, this function is to allow you to convert XML into objects, shared for everyone to reference ...