我对 XML 解析有疑问:
<pricecatalog>
<pricecathdr></pricecathdr>
<listofcatalogdetails>
<catalogitem>
<product>
<productid>1515159115</productid>
</product>
</catalogitem>
<catalogitem>
<product>
<productid>251541851</productid>
</product>
</catalogitem>
<catalogitem>
<product>
<productid>15181158</productid>
</product>
</catalogitem>
</listofcatalogdetails>
</pricecatalog>
我使用 DOM 来解析它:
$doc = new DOMDocument();
$doc->loadXML($this->response);
$items = $doc->getElementsByTagName("catalogitem");
$i = 0;
foreach($items as $itm){
$i++;
}
echo $i;
我认为如果解析成功,我必须得到 2,但我会得到 0。