XPathRecord 0.3

An XML to read-only Python objects library

  Add it to your Download Basket!

 Add it to your Watch List!

0/5

Rate it!
send us
an update
LICENSE TYPE:
Creative Commons Attribution 
USER RATING:
UNRATED
  0.0/5
DEVELOPED BY:
Corey Porter
HOMEPAGE:
www.gemcitysoftware.com
CATEGORY:
ROOT \ Text Editing&Processing \ Markup
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()

Last updated on August 6th, 2009

requirements

#XML markup #Python objects library #XML to objects #XML #objects #library #markup

Add your review!

SUBMIT