【发布时间】:2012-10-06 23:43:06
【问题描述】:
我正在尝试从一个看起来像的结构中提取数据 http://chris.photobooks.com/xml/default.htm?state=8T
使用以下函数,我试图遍历每个产品标签
$dom = new DOMDocument;
$dom->loadXML($resp);
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('ns2', 'http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd');
$xpath->registerNamespace('a', 'http://mws.amazonservices.com/schema/Products/2011-10-01');
foreach($xpath->query('//a:Product') as $product){
echo $product->query('//ns2:ItemAttributes/ns2:Author')->item(0)->nodeValue
}
我现在意识到这是从 for 循环中提取数据的错误方法,但正确的方法是什么?
【问题讨论】: