[SOLVED] Parse real Atom files using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

[SOLVED] Parse real Atom files using PHP

Post by phice »

I've been struggling in finding a solution that allows me to really parse an Atom file, more specifically the YouTube video feed (see: http://gdata.youtube.com/feeds/videos/kHmvkRoEowc)

SimpleXML gets most of it, but not the important parts. If you see near the bottom of the page of that atom file, tags like <media:category> are simply ignored.

Any solutions at all?
Last edited by phice on Wed Oct 24, 2007 1:18 pm, edited 1 time in total.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

could try the PHP DOM functions - they're a little more involved than simpleXML, but quite complete as far as I can tell.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

That is probably the most confusing thing I've ever seen. Upon searching for relative tutorials on PHP DOM, pretty much every tutorial I saw was about parsing very simple RSS files, and not advanced Atom files, as previously linked to in the first post. Any idea where I can find a tutorial or two to specifically parse Atom files?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

pickle wrote:http://simplepie.org/ is nice.
I've already tried that script and it doesn't seem to realize that the link provided (http://gdata.youtube.com/feeds/videos/kHmvkRoEowc) is a real feed.
Skyzyx
Forum Commoner
Posts: 42
Joined: Fri Feb 14, 2003 1:53 am
Location: San Jose, CA

Post by Skyzyx »

Atom feeds are expected to have a parent <feed> element, but YouTube has skipped that oh-so-important element in their new API. SimplePie doesn't think it's an Atom feed because it's not. It IS certainly valid XML, however, so I would recommend an XML parser such as XMLize (http://hansanderson.com/php/xml/).
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

That certainly worked perfectly. Exactly what I was looking for. Thanks so much, Skyzyx.
Post Reply