2

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?

3 Answers 3

3

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

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

Thanks guys :)

Sign up to request clarification or add additional context in comments.

1 Comment

Glad you solved this. Could you please mark this as you're solving answer.
1

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

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

1 Comment

Thanks i tried that but it's not working saying 'invalid expression'
0

Missing closing quote after Medium.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.