note 57252 deleted from ref.xml by bjori
Note Submitter: jbernau at muc dot de
----
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]);
}
}
}
}
?>
|