1, SimpleXML
SimpleXML Convert an XML document to an object, such as:
Element-is converted to a single attribute of the SimpleXMLElement object. When multiple elements exist at the same level, they are placed in the array.
Property-accessed by using an associative array, where the subscript corresponds to the property name.
element data-text data from an element is converted to a string. If an element has more than one text node, it is arranged in the order in which they are found.
SimpleXML is very quick to use when performing basic tasks like the following:
Reading an XML file
Extracting data from an XML string
Edit a text node or property
XML version= "1.0" encoding= "Utf-8"?>
php XML processing Introduction one </
title> <details> Details One </details> </post> <post> <title id= "2" >php XML processing Introduction two
details two
php XML processing introduction three
details three
!--? XML version= "1.0" encoding= "Utf-8"?--"
php XML processing Introduction one
details a
php XML processing Introduction Two
details two
php XML processing introduction three
details three
attributes () Get Properties
PHP /** * Load XML file * /$xml = simplexml_load_file ("Text.xml"); /** * If the XML is a string, you can use the following method, followed by the same method * $xml = simplexml_load_string */ /** * Traversal $xml Object * * foreach ($xml as $key = + $value) { //get property $attr = $value->title->attributes (); echo "Id:". $attr [' id ']. "
"; echo "Title:". $value->title. "
"; echo "Details:". $value->details . "
"; } ? >
$value) { //get property $attr = $value->title->attributes (); echo "Id:". $attr [' id ']. "
"; echo "Title:". $value->title. "
"; echo "Details:". $value->details. "
"; } ? >
http://www.bkjia.com/PHPjc/477236.html www.bkjia.com true http://www.bkjia.com/PHPjc/477236.html techarticle 1. SimpleXML simplexml converts an XML document into an object, such as an element-a single attribute that is converted to a SimpleXMLElement object. When there are multiple elements at the same level, they are ...