我最近正在使用flickr API并且难以解析他们的响应以提取我需要的信息,
这是一个示例回复:
−
<rsp stat="ok">
−
<sizes canblog="0" canprint="0" candownload="1">
<size label="Square" width="75" height="75" source="http://farm3.static.flickr.com/2306/1555710063_d2c1e7e7cd_s.jpg" url="http://www.flickr.com/photos/30561311@N00/1555710063/sizes/sq/" media="photo"/>
<size label="Thumbnail" width="100" height="67" source="http://farm3.static.flickr.com/2306/1555710063_d2c1e7e7cd_t.jpg" url="http://www.flickr.com/photos/30561311@N00/1555710063/sizes/t/" media="photo"/>
<size label="Small" width="240" height="160" source="http://farm3.static.flickr.com/2306/1555710063_d2c1e7e7cd_m.jpg" url="http://www.flickr.com/photos/30561311@N00/1555710063/sizes/s/" media="photo"/>
<size label="Medium" width="500" height="333" source="http://farm3.static.flickr.com/2306/1555710063_d2c1e7e7cd.jpg" url="http://www.flickr.com/photos/30561311@N00/1555710063/sizes/m/" media="photo"/>
<size label="Original" width="1280" height="853" source="http://farm3.static.flickr.com/2306/1555710063_e081a6600a_o.jpg" url="http://www.flickr.com/photos/30561311@N00/1555710063/sizes/o/" media="photo"/>
</sizes>
</rsp>
现在我需要获取其中size属性值为Medium
的source属性值这是我试图用xpath
做的$xml = new SimpleXMLElement($result);
$path = '//size[label="Medium"]@source';
$url $xml->xpath($path);
我尝试了所有类型的xpath查询组合,但我无法找到正确的查询
有关于此的任何想法吗?
答案 0 :(得分:3)
好的,所以看起来正确的组合使这项工作
'//size[@label="Medium"]/@source'
谢谢你们:)
答案 1 :(得分:1)
我认为您@
缺少label
,因为它是attribute
:
'//size[@label="Medium"]@source'
答案 2 :(得分:0)
在Medium之后缺少收盘报价。