Towards MagpieRSS 0.8: repeating elements, attributes, and Atom 1.0

November 5th, 2005

Now that we’ve got the security release out of the way, its time to move on top something a little more interesting. I finally got a chance to add a huge patch from RadGeek (of FeedWordPress fame) that adds:

  • uniform access to attributes
  • support for repeating elements
  • Atom 1.0 support

I’ve struggled for forever to figure out how to provide simple, uniform access to the increasingly rich data that people are syndicating (finally!). Eventually I gave up, and decided that the only solution was to rewrite the parser and make it simple to add per field custom logic. (kind of like the enclosure patch adds custom logic). I never got past the initial sketches.

So I’m thrilled that RadGeek has come up with a syntax (and code!) to extend to add support, while staying transparently backwards compatible. I’ve got out a dev build for people to play with, and written up some of the new features.

Access Repeating Elements

Lets assume we have a basic RSS item, with several dc:subjects:

<title>Some Exciting Title</title>

echo $item['title'] 
=> "Some Exciting Title"

echo $item['dc']['subject']
=> "exciting"

So far, so normal. Now we get special.

echo $item['dc']['subject#2']
=> "example"

echo $item['dc']['subject#3']
=> "whoohoo"

So how many dc:subjects do we have?

echo $item['dc']['subject#']
=> 3

And this isn’t just for dc:subject, it works with whatever elements you like to repeat. (though we’ll need to decide what to do with the Atom link reltype munging hack, I’ll touch on that in a future post)

Access Attributes

Lets assume, we now have an Atom item with a category like:

<category term='atom' scheme='' label='Atom' />

echo $item['category@term']
=> "atom"

echo $item['category@scheme']
=> ""

echo $item['category@label']
=> "Atom"

echo $item['category@']
=> "term,scheme,label"   // that might want to change to an array

And if we had a second category for that item?

<category term='calendar' />

echo $item['category#2@term']
=> 'calendar'

or maybe an RSS 2.0 guid element

<guid isPermaLink="true"></guid>

echo $item['guid']
=> ""

echo $item['guid@ispermalink']
=> "true"

Where from here

So give the dev build a spin, kick the tires etc. This is the largest new feature in a while, and would be good to give it a workout. (ps. I’ve affair the normalization methods are throwing notices currently.)

Also any show stoppers people might see with this new syntax.

Once we’ve got this working smoothly, there are several other new features looking for inclusion in next release.

And finally I’m debating whether to break backward compatibility with how we currently do Atom link munging, in order to get more consistency with this new syntax, and I’d like to get some feedback on that.

Tagged: Uncategorized , , ,

4 responses to “Towards MagpieRSS 0.8: repeating elements, attributes, and Atom 1.0”

  1. Where i sthe code?

    Download doesn’t work!!!

    Please help me 😉

  2. Emmanuel says:

    Well it can be accessed from sourceforge CVS online version, but the following does not work anyway: echo $item[‘category@term’] => “atom”

  3. Jake says:

    Pretty lame to finally add support for those things and then quit… at least have the file somewhere for people to get at… ugh.

  4. mato says:

    could you please reupload the code? the links don’t work. thanx.. i pretty much need the attributed support for magpie but i’m not that good a programmer to fix it myself.. :-/