note 57252 added to ref.xml
| From: | jbernauatmucdotde at osu1 dot php dot net | Date: | Wed, 28 Sep 2005 12:41:55 +0000 |
| Subject: | note 57252 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95923@lists.php.net to get a copy of this message | ||
I liked the xmlparser class by monte (see next comment) very much. So here is my small addition to
it.
usage:
<?php
$p =& new xmlParser();
$p->parse('http://domain.com/rss.xml');
$node = $p->GetNodeByPath("root/leaf/leaf2");
print $node[content];
print $node[attrs][my_attr];
?>
The new member function to class xmlparser:
<?php
function GetNodeByPath($path,$tree = false) {
if ($tree) {
$tree_to_search = $tree;
}
else {
$tree_to_search = $this->output;
}
if ($path == "") {
return null;
}
$arrPath = explode('/',$path);
foreach($tree_to_search as $key => $val) {
if (gettype($val) == "array") {
$nodename = $val[name];
if ($nodename == $arrPath[0]) {
if (count($arrPath) == 1) {
return $val;
}
array_shift($arrPath);
$new_path = implode($arrPath,"/");
return $this->GetNodeByPath($new_path,$val[child]);
}
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57252
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57252&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57252&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57252&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57252&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57252&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57252&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57252&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57252&report=yes
Search -- http://master.php.net/manage/user-notes.php