Jump to content

XPath with PHP 5


repalviglator

Recommended Posts

Can someone tell me why this code doesn't output anything? Is there something extra I need to do? I'm expecting to get the list of places stored in $nodeList.

 

<?php
error_reporting(E_STRICT);

$doc = new DOMDocument;

$doc->load("http://www.43places.com/service/search_places?api_key=1234&q=Ann+Arbor");

$xpath = new DOMXPath($doc);

$nodeList =  $xpath->query("//feed/place");

foreach($nodeList as $node){
var_dump($node);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/40985-xpath-with-php-5/
Share on other sites

I'm not sure why your code isn't working

 

The following code however will extract the "name" values from within each "place" node

<?php
error_reporting(E_STRICT);

$doc = new DOMDocument;

$doc->load("http://www.43places.com/service/search_places?api_key=1234&q=Ann+Arbor");


$nodeList =  $doc->getElementsByTagName('name');


foreach($nodeList as $node){
echo "$node->nodeValue\n";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/40985-xpath-with-php-5/#findComment-198452
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.