php-src/ext/xmlreader/examples/xmlreader_string.php

32 lines
800 B
PHP
Raw Normal View History

2004-04-19 18:55:02 +00:00
<?php
$xmlstring = '<books>
<book num="1">
<title>The Grapes of Wrath</title>
<author>John Steinbeck</author>
</book>
<book num="2">
<title>The Pearl</title>
<author>John Steinbeck</author>
</book>
</books>';
$reader = new XMLReader();
$reader->XML($xmlstring);
while ($reader->read()) {
2005-10-13 21:19:14 +00:00
if ($reader->nodeType != XMLREADER::END_ELEMENT) {
2004-04-19 18:55:02 +00:00
print "Node Name: ".$reader->name."\n";
print "Node Value: ".$reader->value."\n";
print "Node Depth: ".$reader->depth."\n";
2005-10-13 21:19:14 +00:00
if ($reader->nodeType==XMLREADER::ELEMENT && $reader->hasAttributes) {
2004-04-19 18:55:02 +00:00
$attr = $reader->moveToFirstAttribute();
while ($attr) {
print " Attribute Name: ".$reader->name."\n";
print " Attribute Value: ".$reader->value."\n";
$attr = $reader->moveToNextAttribute();
}
}
print "\n";
}
}
?>