|
Posted by CptDondo on 11/30/06 23:28
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.
Thanks,
--Yan
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);
var_dump($baseNode);
$lines = xpath_eval_expression($xpath,'/line',$baseNode);
var_dump($lines);
print "\nOK\n";
foreach($lines->nodeset as $line) {
var_dump($line);
}
}
<root>
<pivot id="1">
<water id="1">
<line id="1">
<bearingTo>120.0</bearingTo>
<WetDry>1</WetDry>
<FwdRev>0</FwdRev>
<event>0</event>
<speed>10</speed>
</line>
<line id="2">
<bearingTo>180.0</bearingTo>
<WetDry>1</WetDry>
<FwdRev>1</FwdRev>
<event>0</event>
<speed>45</speed>
</line>
</water>
<pivot>
</root>
Navigation:
[Reply to this message]
|