Towards MagpieRSS 0.8: repeating elements, attributes, and Atom 1.0
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 rss_parser.inc 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:
<item>
<title>Some Exciting Title</title>
<dc:subject>exciting</dc:subject>
<dc:subject>example</dc:subject>
<dc:subject>whoohoo</dc:subject>
</item>
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='http://del.cio.us/tags' label='Atom' />
echo $item['category@term']
=> "atom"
echo $item['category@scheme']
=> "http://del.cio.us/tags"
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">http://inessential.com/2002/09/01.php#a2</guid>
echo $item['guid']
=> "http://inessential.com/2002/09/01.php#a2"
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.