You are here:  » Complex feed item


Complex feed item

Submitted by bruce2005 on Sun, 2007-01-07 14:08 in

Hi,

Newbie here...I am trying to extract one record from an xml file. So far no parser I have seen can.
Example:
A google media rss file has:
rss version="2.0" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:media="http://search.yahoo.com/mrss"
Channel
........
items
...
media:group
media:content url="xxx"
media:content url="xxx"
media:thumbnail url="xxx"
/media:group

Can magic parser get the value of "xxx" and print to the page where I want it?
I mean separately? Especially for me to be able to get the image url to show it as an image and place it where I want it

If yes then definitely more than one sale here :)
Thanks

Thanks

Submitted by support on Sun, 2007-01-07 14:22

Hello Bruce,

Can you post a link to the actual feed that you are trying to parse? Or you can email me the link if you don't want to make it public - reply to your forum registration email is the easiest way...

Cheers,
David.

Submitted by bruce2005 on Sun, 2007-01-07 14:27

http://www.bkdesign.ca/_media/musica.php

Thanks for the quick answer!

Submitted by support on Sun, 2007-01-07 14:41

Hi,

As it is a standard RSS feed there is no problem in terms of parsing the basic RSS fields. Here is your feed loaded into the Magic Parser demo tool:

http://www.magicparser.com/demo?fileID=45A104E521DD7&record=1

Please note - the actual script does not produce that table output like that; what you see is just how the demo page displays each $record using PHPs foreach function.

You will see from that output that you can indeed access items like:

MEDIA:GROUP/MEDIA:CONTENT-URL

In your code, you would access the value of the URL using something like this:

print $record["MEDIA:GROUP/MEDIA:CONTENT-URL"];

However, notice that there are multuple MEDIA:GROUP sets per record in this feed. This makes it somewhat more complicated if you wish to access subsequent values. You can do something like this:

if (isset($record["MEDIA:GROUP/MEDIA:CONTENT@1"]))
{
// we have a second MEDIA:GROUP
print $record["MEDIA:GROUP/MEDIA:CONTENT@1-URL"];
}

You can also write a loop to extract multiple additional items by using a counter 1..2..3..n and using the counter as part of the key to see if it exists in the $record:

<?php
function myRecordHandler($record)
{
  
$i 1;
  while(
issset($record["MEDIA:GROUP/MEDIA:CONTENT@".$i]))
  {
    
$url $record["MEDIA:GROUP/MEDIA:CONTENT@".$i."-URL"];
    
$i++;
  }
}
?>

Hope this helps,
Regards,
David.

Submitted by bruce2005 on Sun, 2007-01-07 14:46

wow!

I have driven myself nuts for three days trying to get other parsers to do the above.
It doesn't only help, I'm putting your name in for the nobel prize, and you should run for president too!
;)

Checking my paypal now...
Thank you very much.
I cannot thank you enough, this is awesome.