PDA

View Full Version : Multiple Values, same elements - Only wanting one


curb
05-09-2007, 07:11 PM
I'm using xpath to get specific image link from my birthday pictures. I seem to fetch all the urls that contains "media:content" but I'm trying to get only one. There's two formats I have trouble with. I'm not sure if it makes a difference that 'media:group' is there.

$birthday = $item->xpath("//media:content");
$birthday = $birthday[$i]['url'];


How would I only pull "http://www.site.com/event/birthday/2.jpg" ?
<item>
<media:group>
<media:content url="http://www.site.com/picture/birthday/1.jpg"/>
<media:content url="http://www.site.com/event/birthday/2.jpg"/>
<media:content url="http://www.site.com/event/wedding/1.jpg"/>
<media:content url="http://www.site.com/picture/wedding/2.jpg"/>
</media:group>
</item>

and

How would I only pull "http://www.site.com/picture/birthday/1b.jpg" ?

<item>
<media:content url="http://www.site.com/picture/birthday/1a.jpg"/>
<media:content url="http://www.site.com/picture/birthday/1b.jpg"/>
<media:content url="http://www.site.com/picture/birthday/1c.jpg"/>
</item>

Alex Vincent
05-10-2007, 05:13 AM
"//media:content[@url='http://www.site.com/event/birthday/2.jpg']"

That might do it. I've been messing with XPath a little. But then, if you already have the URI, why are you trying to get it? :)

curb
05-10-2007, 07:38 AM
Is there a way to do some sort of wild strings to find an element containing a keyword/string? I wouldn't be able to predict the exact filename, just the directory (event,picture,birthday,wedding).

If this isn't possible, how would I go about it and fetch only one media:content from row 1,2,3 or 4 for each item?

There's multiple items with different filenames so I can't add a direct image url. Here's an example of how it would look like.

<item>
<user>curb</user>
<media:group>
<media:content url="http://www.site.com/picture/birthday/1.jpg"/>
<media:content url="http://www.site.com/event/birthday/2.jpg"/>
<media:content url="http://www.site.com/event/wedding/1.jpg"/>
<media:content url="http://www.site.com/picture/wedding/2.jpg"/>
</media:group>
</item>
<item>
<user>Alex Vincent</user>
<media:group>
<media:content url="http://www.site.com/picture/sports/1s.jpg"/>
<media:content url="http://www.site.com/event/sports/cr32c.jpg"/>
<media:content url="http://www.site.com/event/travel/1asd.jpg"/>
<media:content url="http://www.site.com/picture/travel/2asd.jpg"/>
</media:group>
</item>

Alex Vincent
05-10-2007, 08:42 PM
What specifically are your search terms? "birthday/1.jpg"?

curb
05-10-2007, 09:04 PM
Nm I found an alternative route. Thanks anyways.