XPathRecord is a software that seeks to take some of the grunt work out of transforming XML in to objects. Follows is a very brief example of an RSS parser.
import xpathrecord
class RSSPost(xpathrecord.XPathRecord):
title = xpathrecord.TextField('title/text()')
link = xpathrecord.TextField('link/text()')
pubdate = xpathrecord.DatetimeField('pubDate/text()',
'%a, %d %b %Y %H:%M:%S +0000')
def main():
import libxml2, urllib2, sys
for feed_url in sys.argv[1:]:
doc = urllib2.urlopen(feed_url).read()
dom = libxml2.parseMemory(doc, len(doc))
for post in RSSPost.records(dom, '//item'):
print 'Post:'
print ' title: %s' % post.title()
print ' link: %s' % post.link()
print ' date: %s' % post.pubdate()
if '__main__' == __name__:
main()
Product's homepage
Requirements:
· Python