【发布时间】:2021-11-12 17:35:45
【问题描述】:
我正在尝试循环通过从 API 调用获得的 XML 输出。 XML 的结构如下所示:
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<products>
<product>
<id>97</id>
<id_manufacturer>0</id_manufacturer>
<id_supplier>0</id_supplier>
<width>0.000000</width>
<height>0.000000</height>
<depth>0.000000</depth>
<weight>1.127272</weight>
<quantity_discount>0</quantity_discount>
<on_sale>0</on_sale>
<online_only>0</online_only>
<minimal_quantity>1</minimal_quantity>
<price>37.000000</price>
</product>
<product>...</product>
<product>...</product>
<product>...</product>
<product>...</product>
</products>
</prestashop>
我想循环浏览所有产品并获取例如价格。 我已经尝试过不同的方法,例如:
$opt = array(
'resource' => 'products',
'display' => 'full',
'filter[id]' => $_GET['id'],
'postXml' => 'asXML'
);
$xml = $webService->get($opt); // getting the xml data as shown above
foreach ($xml->products->product as $p) {
echo $p->attributes()->price;
}
但结果不会显示任何内容... 如果您能帮助我并可能有解决方案,我会很高兴。
【问题讨论】: