Jump to content

Recommended Posts

Hi - I am trying to use simpleXML to parse a picasaWeb XML feed and I am running into a bit of trouble.

 

the URL of the picasaweb feed I am using is:

http://picasaweb.google.com/data/feed/api/user/blairdee2000/albumid/5149975922288869729?kind=photo&access=public&thumbsize=144c&imgmax=512

 

right now i am just trying to spit out the thumbnail image url and the title and description for each.

 

so the thumbnail url should be at:

feed->entry->media:group->media:thumbnail in the url attribute

 

and the title should be found at

feed->entry->media:group->media:title

 

and the description should be found at

feed->entry->media:group->media:description

 

so initially i thought the following code would work:

$xml = simplexml_load_file($feedURL);
foreach($xml->entry as $entry)
{
	imgTitle = entry->media:group->media:title;
	imgDescrip = entry->media:group->media:description;
	thumbURL = entry->media:group->media:thumbnail['url'];
	echo("<strong>Title:" . $imgTitle . "</strong><br/>");
	echo("<strong>Description:" . $imgDescrip . "</strong><br/>");
	echo("<img src='" . $thumbURL . "'><br/>");

}

 

but that didnt work - it seems as though the : in the node names is throwing it off.  sorry I am a relative newbie - i am sure that the colon has a special meaning but i dont know what it is.

 

so i ended up finding some code that does work but it seems more complex than it  needs to be:

$xml = simplexml_load_file($feedURL);

foreach($xml->entry as $entry)
{
	$imgTitleArray = $entry->xpath('./media:group/media:title');
	$imgTitle = $imgTitleArray[0];

	$imgDescripArray = $entry->xpath('./media:group/media:description');
	$imgDescrip = $imgDescripArray[0];

	$imgThumbArray = $entry->xpath('./media:group/media:thumbnail');
	$imgThumbAttributes = $imgThumbArray[0]->attributes();
	$imgThumb = $imgThumbAttributes[0];

	echo("<strong>Title:" . $imgTitle . "</strong><br/>");
	echo("<strong>Description:" . $imgDescrip . "</strong><br/>");
	echo("<img src='" . $imgThumb . "'><br/><br/>");
}

 

looks like i have to use the xpath function to reference these special nodes which returns an array.  then i have to use the attributes function to return an array of the attributes.  then i have to reference the attributes array item by its numerical index... i dunno this seems more complex than it needs to be... am I right?  or is that just how it has to be done.  if someone could provide some guidance to get me in the right track here I would appreciate it.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.