I am attempting to use xpath to run a program and parse out xml data for repricing books. However, when I run the program I get the following errors:
PHP Warning: SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: Invalid expression
and
PHP Warning: SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: xmlXPathEval: evaluation failed
both on line 242 which is the line of $result...:
//function to check if child nodes exist for pricing
function xml_child_exists($xml, $childpath)
{
$result = $xml->xpath($childpath);
if (isset($result)) {
return true;
} else {
return false;
}
}
This function is run here:
// check to see if there are values
if(xml_child_exists($parsed_xml, $current->AttributeSets->children('ns2', true)->ItemAttributes->ListPrice->Amount))
{
$listPrice = $current->AttributeSets->children('ns2', true)->ItemAttributes->ListPrice->Amount;
} else {
$listPrice = 0;
}
Then I finally am ending up with:
PHP Fatal error: Call to a member function children() on a non-object in repricemws.php on line 67
Line 67 is where the function is being called.
What is wrong with this code and how do I make it so that it will run correctly?