473,385 Members | 1,661 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

xpath XML and PHP4

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>
Nov 30 '06 #1
1 2970
For a relative path, try the tag name without a leading slash:

xpath_eval_expression($xpath,'line',$baseNode);

More on absolute and relative location paths:

http://www.w3schools.com/xpath/xpath_axes.asp

CptDondo wrote:
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>
Dec 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tim Tyler | last post by:
I'm sure this is a FAQ - but I could not find a coherent statement of the answer: Some of my clients want PHP4. Other ones want PHP5. Can I run both PHP4 and PHP5 under the same instance of...
1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
5
by: laks | last post by:
Hi I have the following xsl stmt. <xsl:for-each select="JOB_POSTINGS/JOB_POSTING \"> <xsl:sort select="JOB_TITLE" order="ascending"/> This works fine when I use it. But when using multiple...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
2
by: Stefan Huber | last post by:
Hi I've got a really strange problem, and can't find out why it's not working as intended. in order to use php4 and 5 together on a webserver and the requirement for running as different...
2
by: 张韡武 | last post by:
We have preffered language set as variable in xslt: <xsl:variable name="preferred_language"> zh </xsl:variable> Data: <name xml:lang="de">Raw Materials (Mining incl.)</name> <name...
12
by: Drazen Gemic | last post by:
How long will PHP4 be supported ? When is PHP4 end of life scheduled ? DG
3
by: doctorhardik | last post by:
hai all i am try configure php4.3.9 on my FC-3 machine. and my mysql database version 5.0.1, in phpinfo file it show mysql but when i run php -v command it show error like
8
by: FFMG | last post by:
Hi, I am slowly moving my code to php5. But I would like to make it backward compatible in case something bad happens, (and to make sure I understand what the changes are). The way the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.