1<?php 2$xmlstring = '<books> 3 <book num="1"> 4 <title>The Grapes of Wrath</title> 5 <author>John Steinbeck</author> 6 </book> 7 <book num="2"> 8 <title>The Pearl</title> 9 <author>John Steinbeck</author> 10 </book> 11</books>'; 12 13$reader = new XMLReader(); 14$reader->XML($xmlstring); 15while ($reader->read()) { 16 if ($reader->nodeType != XMLREADER::END_ELEMENT) { 17 print "Node Name: ".$reader->name."\n"; 18 print "Node Value: ".$reader->value."\n"; 19 print "Node Depth: ".$reader->depth."\n"; 20 if ($reader->nodeType==XMLREADER::ELEMENT && $reader->hasAttributes) { 21 $attr = $reader->moveToFirstAttribute(); 22 while ($attr) { 23 print " Attribute Name: ".$reader->name."\n"; 24 print " Attribute Value: ".$reader->value."\n"; 25 $attr = $reader->moveToNextAttribute(); 26 } 27 } 28 print "\n"; 29 } 30} 31?> 32