note 81148 added to ref.xmlreader
| From: | itari at osu1 dot php dot net | Date: | Fri, 15 Feb 2008 16:30:18 +0000 |
| Subject: | note 81148 added to ref.xmlreader | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136180@lists.php.net to get a copy of this message | ||
<?php
function parseXML($node,$seq,$path) {
global $oldpath;
if (!$node->read())
return;
if ($node->nodeType != 15) {
print '<br/>'.$node->depth;
print '-'.$seq++;
print ' '.$path.'/'.($node->nodeType==3?'text() =
':$node->name);
print $node->value;
if ($node->hasAttributes) {
print ' [hasAttributes: ';
while ($node->moveToNextAttribute()) print '@'.$node->name.' =
'.$node->value.' ';
print ']';
}
if ($node->nodeType == 1) {
$oldpath=$path;
$path.='/'.$node->name;
}
parseXML($node,$seq,$path);
}
else parseXML($node,$seq,$oldpath);
}
$source = "<tag1>this<tag2 id='4'
name='foo'>is</tag2>a<tag2
id='5'>common</tag2>record</tag1>";
$xml = new XMLReader();
$xml->XML($source);
print htmlspecialchars($source).'<br/>';
parseXML($xml,0,'');
?>
Output:
<tag1>this<tag2 id='4' name='foo'>is</tag2>a<tag2
id='5'>common</tag2>record</tag1>
0-0 /tag1
1-1 /tag1/text() = this
1-2 /tag1/tag2 [hasAttributes: @id = 4 @name = foo ]
2-3 /tag1/text() = is
1-4 /text() = a
1-5 /tag2 [hasAttributes: @id = 5 ]
2-6 /text() = common
1-7 /text() = record
----
Server IP: 69.147.83.197
Probable Submitter: 79.220.97.213
----
Manual Page -- http://www.php.net/manual/en/ref.xmlreader.php
Edit -- https://master.php.net/note/edit/81148
Del: integrated -- https://master.php.net/note/delete/81148/integrated
Del: useless -- https://master.php.net/note/delete/81148/useless
Del: bad code -- https://master.php.net/note/delete/81148/bad+code
Del: spam -- https://master.php.net/note/delete/81148/spam
Del: non-english -- https://master.php.net/note/delete/81148/non-english
Del: in docs -- https://master.php.net/note/delete/81148/in+docs
Del: other reasons-- https://master.php.net/note/delete/81148
Reject -- https://master.php.net/note/reject/81148
Search -- https://master.php.net/manage/user-notes.php