tags:

views:

339

answers:

3

Hi, i'm playing around with flickr API lately and having difficulties in parsing their response to extract the info i need,

here is a sample response:

−
<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>

now i need the get just the source attribute value where the size attribute value is Medium

here is how i'm trying to do that with xpath

$xml = new SimpleXMLElement($result);
$path = '//size[label="Medium"]@source';
$url  $xml->xpath($path);

i tried all kind of xpath query combinations but i cant get to the right query

any ideas on that?

A: 

Missing closing quote after Medium.

Ollie Saunders
sorry just typing error :)
Yaniv
+1  A: 

I think you have a mising @ for label because it's an attribute:

'//size[@label="Medium"]@source'
najmeddine
Thanks i tried that but it's not working saying 'invalid expression'
Yaniv
+4  A: 

OK so looks like the right combination that made this work is

'//size[@label="Medium"]/@source'

Thanks guys :)

Yaniv
Glad you solved this. Could you please mark this as you're solving answer.
Ollie Saunders