warrenrapson
asked on
Quick php xpath question
Hi all,
One hour has pass and I can't work out how to get the result of an xpath query!!!
With the below, how can I return one node's value? I mean, how would I say
for each result
echo show_me_the_streetname_val ue
next
???
Thanks,
Warren
One hour has pass and I can't work out how to get the result of an xpath query!!!
With the below, how can I return one node's value? I mean, how would I say
for each result
echo show_me_the_streetname_val
next
???
Thanks,
Warren
<?php
$xmlDocument = new DOMDocument();
if ($xmlDocument->load('vw_WebsitePropertyData.xml')) {
$xpath = new DOMXPath($xmlDocument);
$nodeList = $xpath->query('/dataroot/vw_WebsitePropertyData[RentPerWeek>22]', $xmlDocument);
}
?>
ASKER
Great!
So how would I get a named value from that array object?
Eg.
echo 'Street Name: ' . ?????????????
So how would I get a named value from that array object?
Eg.
echo 'Street Name: ' . ?????????????
echo 'Street Name:' . $result[0]
If you have multiple values put it into a for loop like this:
If you have multiple values put it into a for loop like this:
for($i = 0; $i >= count($result) ; $i++)
{
echo 'Street Name: ' . $result[$i];
}
Should work.
Ops made a mistake, sorry.
for($i = 0; $i <= count($result) ; $i++)
{
echo 'Street Name: ' . $result[$i];
}
ASKER
I tried that first, and I could see how that would work, but the array contains the SimpleXMLElement object. Below is part of the print_r output
SimpleXMLElement Object ( [ID] => 2 [Contact] => Paul Bradford [Street] => 10 Jeffson Street..............
So I am still lost as to how to pluck the 'street' value from this result set.
SimpleXMLElement Object ( [ID] => 2 [Contact] => Paul Bradford [Street] => 10 Jeffson Street..............
So I am still lost as to how to pluck the 'street' value from this result set.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant!!
Thanks for your help.
Thanks for your help.
Open in new window