I’ve encountered an Atom feed that I’d like to parse and extract the data. I’m familiar with parsing an RSS feed, but haven’t used Atom feeds. If you’ve worked with Atom feeds, I’d appreciate any help you can offer. If you have any sample code showing how you’re parsing a feed would help a lot. I’m assuming it’s similar to parsing an rss 2.0 feed, but there must be differences because so far I haven’t been successful in bringing any data in.
sub main()
feed=readasciifile("pkg:/feed.xml")
xml=createobject("roXMLElement")
obj=createobject("roAssociativeArray")
if xml.parse(feed) then
obj.title=xml.title.gettext()
obj.subtitle=xml.subtitle.gettext()
obj.links=[]
for each link in xml.link
obj.links.push(link.getattributes())
end for
obj.id=xml.id.gettext()
obj.updated=xml.updated.gettext()
for each element in xml.author.getchildelements()
obj[element.getname()]=element.gettext()
end for
entry=xml.entry
obj["element"]=[]
for each item in entry.getchildelements()
arr={}
arr[item.getname()]=element.gettext()
arr[item.getname()+"_attribute"]=item.getattributes()
obj.element.push(arr)
end for
else
?"parse failed"
end if
stop
end sub
It manages, through a variety of ways, to get (I think) all the attributes into a variable of one sort or another.
One way I didn’t include in this example, if I just wanted the href part of a link, I could have done:
for each link in xml.link
obj.links.push(link@href)
end for
When the code finishes running, print out the variable obj:
Thanks again Joel. That looks like a very good example. It’ll give me a good start on trying to parse an atom feed. I appreciate you throwing that together and posting it. I’ll play with it and let you know if I have any questions.