This example describes the use of the SimpleXML function in PHP, which allows you to transform XML into objects and share them for your reference. The specific analysis is as follows:
The SimpleXML function allows you to convert XML to an object, and you can work with the object as you would any other object by using a normal property selector or an array iterator. Some of these functions require the latest PHP version.
Installation: The SimpleXML function is part of the PHP core and can be used without installation, and the code is as follows:
Copy Code code as follows:
<?php
Return all content as an object
$lib = simplexml_load_file ("Cet4.xml");
Returns the acquired item node as an array
$items = $lib->item;
$wordsLength = sqlserver/42852.htm Target=_blank >count ($items);
Gets the next node value of all nodes
for ($i =0; $i < $wordsLength; $i + +) {
$word = $items [$i];
echo $word->word. '-----' $word->trans. '-----'. $word->phonetic. ' <br/> ';
}
SimpleXML combining XPath is omnipotent
$words = $lib->xpath ("//word");
Methods to get Properties
echo $words [0][' Add ']. ' <br/> ';
echo $items [0][' PP '];
?>
Related functions are described below:
Function |
Describe |
PHP version |
__construct () |
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 () |
To get an XML string from the SimpleXML element |
5 |
Attributes () |
Gets the properties of the SimpleXML element |
5 |
Children () |
Gets the child nodes of the specified node |
5 |
Getdocnamespaces () |
Getting namespaces for XML documents |
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 () |
Getting SimpleXMLElement objects from a DOM node |
5 |
Simplexml_load_file () |
Getting SimpleXMLElement objects from an XML document |
5 |
Simplexml_load_string () |
To get a SimpleXMLElement object from an XML string |
5 |
XPath () |
Run an XPath query on XML data |
5 |
I hope this article will help you with your PHP program design.