【发布时间】:2011-06-16 04:02:23
【问题描述】:
我正在尝试显示从 xml 结果返回的最大图像 url。到目前为止,返回的最大的是 400 高,所以我硬编码了 400 英寸。如果可能的话,我想选择最大的,以防将来我得到的结果中没有 400 高的图像。
我试过了
$x = file_get_contents($url);
$xml = simplexml_load_string($x);
$imageURL=$xml->categories->category->items->product->images->image[@height='400']->sourceURL;
这给了我“语法错误,意外 '=',期待 ']'”。
我也试过了:
$imageURL= $xml->xpath("/categories/category/items/producct/images/image[@height='400']/sourceURL");
但是有一个错误的链接。 这是 XML:
<images>
<image available="true" height="100" width="100">
<sourceURL>
Someurl.com
</sourceURL>
</image>
<image available="true" height="200" width="200">
<sourceURL>
Someurl.com
</sourceURL>
</image>
<image available="true" height="300" width="300">
<sourceURL>
Someurl.com
</sourceURL>
</image>
<image available="true" height="400" width="400">
<sourceURL>
Someurl.com
</sourceURL>
</image>
<image available="true" height="399" width="400">
<sourceURL>
Someurl.com
</sourceURL>
</image>
</images>
有什么想法吗?
【问题讨论】: