xpath XML and PHP4

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am working on an embedded platform.  I have php4 installed along with  
libxml, so I have working DOMXML and xpath stuff...

But I can't figure out how to use it.

I am trying to get the base node of a schedule; I've attached a small
portion of my XML file below.  What I would like to do is to get the
root of a schedule, and then iterate with foreach through all of the
children.  This is the function I came up with and of course it doesn't
work.  I don't understand how I am supposed to work with the object that
the xpath_eval[_expression] returns.  I've also tried the child_nodes
method and that fails as well.



     function loadSchedule($pivotID, $schedName, $schedNum) {
     $dom = domxml_open_file("/tmp/test.conf");
     $xpath = xpath_new_context($dom);
     // find base node for our schedule
     $pat = '//root/pivot[@id="' . $pivotID . '"]/'
         . $schedName . '[@id="' . $schedNum . '"]';
     print $pat;
     $baseNode = xpath_eval($xpath,$pat);
     $lines = xpath_eval_expression($xpath,'/line',$baseNode);
     print "\nOK\n";
     foreach($lines->nodeset as $line) {

     <pivot id="1">
         <water id="1">
             <line id="1">
             <line id="2">

Re: xpath XML and PHP4

For a relative path, try the tag name without a leading slash:


More on absolute and relative location paths:


CptDondo wrote:
Quoted text here. Click to load it

Site Timeline