Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > note 57252 deleted from ref.xml by bjori
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 21st December 08:49
bjori
External User
 
Posts: 1
Default 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]);
}
}
}
}
?>
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666