xpath_eval problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lettie_dude
Forum Commoner
Posts: 65
Joined: Thu Dec 07, 2006 10:10 am

xpath_eval problems

Post by lettie_dude »

Hi I have a problem with some code that I need to implement for a news feed. The feed is xml from a news source site. The problem I have is that the xpath_eval function does not seem to be reading the dom object.

I am running on php 4.4.1 on a Linux system. domxml is enabled along with XPath support.

Apparently the code should work with php 4 and has worked for other users of the news feed. The guys providing the code seem to think it may be a problem with the version of the DOM/XML API Version which my hosts are using version: 20020815

I get the following error message when trying to run the code:

Warning: xpath_eval(): Invalid expression in /path of file on line 29

Warning: xpath_eval(): xmlXPathEval: evaluation failed in /path of file on line 29
Article found: 0

Any help much appreciated.


Code is as follows:

Code: Select all

$dataFile = fopen ('http://newssiteurl.co.uk/?c21c0905-b9ca-43ee-87be-7e4308406da6','r')
or die("Error Loading XMl");

if ( $dataFile )
{
while (!feof($dataFile))
{
$buffer .= fgets($dataFile, 4096); 
}
fclose($dataFile);
}
else
{
die( "fopen failed for $filename" ) ;
}

// Loading xml into a DOM object.
$dom = domxml_open_mem($buffer);
$xpc = xpath_new_context($dom);

// Selecting nodes matching node "Article" using xpath_eval command and passing it the xpath context
$nodes = xpath_eval($xpc, "//Article/");
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

lettie_dude wrote://Article/
remove the trailing /
lettie_dude
Forum Commoner
Posts: 65
Joined: Thu Dec 07, 2006 10:10 am

xpath probs

Post by lettie_dude »

Many thanks volka seems to have done the trick.

Cheers
Post Reply