Back to index

php5  5.3.10
xmlreader_string.php
Go to the documentation of this file.
00001 <?php
00002 $xmlstring = '<books>
00003  <book num="1">
00004   <title>The Grapes of Wrath</title>
00005   <author>John Steinbeck</author>
00006  </book>
00007  <book num="2">
00008   <title>The Pearl</title>
00009   <author>John Steinbeck</author>
00010  </book>
00011 </books>';
00012 
00013 $reader = new XMLReader();
00014 $reader->XML($xmlstring);
00015 while ($reader->read()) {
00016        if ($reader->nodeType != XMLREADER::END_ELEMENT) {
00017               print "Node Name: ".$reader->name."\n";
00018               print "Node Value: ".$reader->value."\n";
00019               print "Node Depth: ".$reader->depth."\n";
00020               if ($reader->nodeType==XMLREADER::ELEMENT && $reader->hasAttributes) {
00021                      $attr = $reader->moveToFirstAttribute();
00022                      while ($attr) {
00023                             print "   Attribute Name: ".$reader->name."\n";
00024                             print "   Attribute Value: ".$reader->value."\n";
00025                             $attr = $reader->moveToNextAttribute();
00026                      }
00027               }
00028               print "\n";
00029        }
00030 }
00031 ?>