| <? |
| |
| // This class implements something similar to XPath. Since versions of PVP |
| // pre 5.0 don't include XPath implementations |
| |
| class XMLHandler{ |
| var $_tree; |
| |
| function XMLHandler($tree){ |
| $this->_tree = $tree; |
| } |
| |
| function GetNodeByPath($path,$tree=false){ |
| if ($path == "") |
| return null; |
| else |
| $path = strtolower($path); |
| |
| if ($tree) |
| $tree_to_search = $tree; |
| else |
| $tree_to_search = $this->_tree; |
| |
| $arrPath = explode('/',$path); |
| if ($arrPath[0] == "" && count($arrPath) > 1) |
| array_shift($arrPath); |
| |
| foreach($tree_to_search as $key => $val){ |
| if (gettype($val) == "array"){ |
| $nodename = strtolower($val[name]); |
| if ($nodename == $arrPath[0]){ |
| if (count($arrPath) == 1) |
| if (isset($val[content][child])) |
| return $val[content][child]; |
| else |
| return $val; |
| array_shift($arrPath); |
| $new_path = implode($arrPath,"/"); |
| |
| return $this->GetNodeByPath($new_path,$val[child]); |
| } |
| } |
| } |
| } |
| |
| } |
| ?> |