Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php解析xml xpath时出错_Php_Xml_Xpath_Xml Parsing - Fatal编程技术网

使用php解析xml xpath时出错

使用php解析xml xpath时出错,php,xml,xpath,xml-parsing,Php,Xml,Xpath,Xml Parsing,我正试图使用xpath运行一个程序并解析xml数据,以便为书籍重新定价。但是,当我运行该程序时,会出现以下错误: PHP Warning: SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: Invalid expression } 此函数在此处运行: // check to see if there are values if

我正试图使用xpath运行一个程序并解析xml数据,以便为书籍重新定价。但是,当我运行该程序时,会出现以下错误:

PHP Warning:  SimpleXMLElement::xpath() [<a href='simplexmlelement.xpath'>simplexmlelement.xpath</a>]: Invalid expression
}

此函数在此处运行:

// 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行是调用函数的地方


这段代码有什么问题?如何使其正确运行?

是否
$current->attributeset->children('ns2',true)->itemtattributes->ListPrice->Amount
包含有效的XPath表达式

从调用链的外观来看,您正在提取单个值,例如“5.00”,并将其直接传递给xpath查询执行器。这是行不通的,会产生错误消息


后续行动:

好的,
Amount
是一个价格,大概是5美元或5美元,对吗?这意味着您正使用该字符串作为xpath查询,基本上执行以下操作:

$result = $xml->xpath('$5.00');
这不是有效的xpath表达式。所以$result不是文档中匹配节点的列表,它实际上是一个布尔值FALSE


然后对该值执行isset()。变量设置为(布尔值为false),因此您的函数返回TRUE

是,它是一个有效的XPath表达式,应该提取一个值。该如何写入以正确执行?
…->Amount
应返回类似于
//div
或其他内容的内容。现在还什么?金额是还书的价格。如果您的意思是从函数中,如果有价格,则返回true;如果没有价格,则返回false。
PHP Fatal error:  Call to a member function children() on a non-object in repricemws.php on line 67
$result = $xml->xpath('$5.00');