PHP uses XmlReader to read XML data samples, Xmlreaderxml
There is an XML file with the following content:
Copy the Code code as follows:
<?xml version= "1.0"?>
Simpsons
FOX
8:00AM-5:00pm
30
Law & Order
Nbc
8:00AM-5:00pm
60
Here we use the XmlReader extension to parse and process the file, and XmlReader also has the advantage of reading the data in the form of stream, even though it can still be handled in the face of a very large XML file. Here's how we deal with the above file:
Copy the Code code as follows:
$INDEXURL = ' http://www.xxx.com/xxx.xml ';
$reader = new XMLReader ();
$reader->open ($INDEXURL);
$countElements = 0;
while ($reader->read ()) {
if ($reader->nodetype = = xmlreader::element) {
$nodeName = $reader->name;
}
if ($reader->nodetype = = Xmlreader::text &&!empty ($nodeName)) {
Switch ($nodeName) {
Case ' name ':
$name = $reader->value;
Break
Case ' channel ':
$channel = $reader->value;
Break
Case ' start ':
$start = $reader->value;
Break
Case ' duration ':
$duration = $reader->value;
Break
}
}
}
$reader->close ();
http://www.bkjia.com/PHPjc/934935.html www.bkjia.com true http://www.bkjia.com/PHPjc/934935.html techarticle in PHP, using XmlReader to read XML data examples, Xmlreaderxml has an XML file that reads as follows: The copy code code is as follows: XML version= "1.0" shows show Namesimpsons/name channelfox/ ...