0
我试图从看起来像 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循环中提取数据的错误方法,但是正确的方法是什么?
我希望我能之前尝试过了,但我只是用str_replace()函数来替换所有命名空间去的廉价和肮脏的方式。不管怎么说,还是要谢谢你 –