Page 1 of 1
[SOLVED] Parse real Atom files using PHP
Posted: Mon Oct 22, 2007 12:55 am
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?
Posted: Mon Oct 22, 2007 1:00 am
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.
Posted: Mon Oct 22, 2007 1:17 am
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?
Posted: Mon Oct 22, 2007 3:09 am
by pickle
Posted: Tue Oct 23, 2007 1:06 pm
by phice
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.
Posted: Tue Oct 23, 2007 11:27 pm
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/).
Posted: Wed Oct 24, 2007 1:17 pm
by phice
That certainly worked perfectly. Exactly what I was looking for. Thanks so much, Skyzyx.