agmark
14 years agoVisitor
Atom feeds
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 he...
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
for each link in xml.link
obj.links.push(link@href)
end for
BrightScript Debugger> print obj
name: John Doe
element: <Component: roArray>
email: johndoe@example.com
subtitle: A subtitle.
updated: 2003-12-13T18:30:02Z
id: urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6
title: Example Feed
links: <Component: roArray>
BrightScript Debugger> print obj.element
<Component: roAssociativeArray>
<Component: roAssociativeArray>
<Component: roAssociativeArray>
<Component: roAssociativeArray>
<Component: roAssociativeArray>
<Component: roAssociativeArray>
<Component: roAssociativeArray>
BrightScript Debugger> ?obj.element[0]
title: johndoe@example.com
title_attribute: <Component: roAssociativeArray>
BrightScript Debugger> ?obj.element[1]
link: johndoe@example.com
link_attribute: <Component: roAssociativeArray>
BrightScript Debugger> ?obj.element[1].link_attribute
href: http://example.org/2003/12/13/atom03
BrightScript Debugger> ?obj.links
http://example.org/feed/
http://example.org/