当我尝试从 XML 文件中提取信息时出现此错误。获取信息的代码是:
//retrieve amazon data
$parsed_xml = amazon_xml($isbn);
$amazonResult = array();
//print_r($parsed_xml); die;
$current = $parsed_xml->ListMatchingProductsResponse->ListMatchingProductsResult->Products->Product;
//if($parsed_xml) {
$amazonResult = array(
'Title' => $current->AttributeSets->children('ns2')->ItemAttributes->Title,
'SalesRank' => $current->SalesRankings->SalesRank->Rank,
'ListPrice' => $current->AttributeSets->ItemAttributes->ListPrice->Amount,
'ImageURL' => $current->AttributeSets->ItemAttributes->SmallImage->URL,
'DetailURL' => $current->AttributeSets->ItemAttributes->SmallImage->URL,
XML文件是:
<?xml version="1.0"?>
<ListMatchingProductsResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<ListMatchingProductsResult>
<Products xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Product>
<AttributeSets>
<ns2:ItemAttributes xml:lang="en-US">
<ns2:Title>JavaScript: The Missing Manual</ns2:Title>
当我运行它时,我得到一个空值,当我检查错误日志时,我得到:Call to a member function children() on a non-object in ... 在第 52 行。违规行是:
'Title' => $current->AttributeSets->children('ns2')->ItemAttributes->Title,
唯一具有 ns2 命名空间的项是 ItemAttributes 和 Title。
如何更正此问题以便获取标题信息?谢谢