我正在尝试使用 xpath 来运行程序并解析出 xml 数据以重新定价书籍。但是,当我运行程序时,出现以下错误:
PHP Warning: SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: Invalid expression
和
PHP Warning: SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: xmlXPathEval: evaluation failed
都在第 242 行,这是 $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;
}
}
这个函数在这里运行:
// 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;
}
然后我终于结束了:
PHP Fatal error: Call to a member function children() on a non-object in repricemws.php on line 67
第 67 行是调用函数的位置。
这段代码有什么问题,我该如何让它正确运行?