First of all, let me state that I did google and find something
"similar", called EaseXML (http://xmlobject.base-art.net/). But looking
at the example, this didn't feel very natural to me; albeit better than
most generators I've seen.
What I have in mind is a way to model your XML document in terms of
python classes, much like SQLObject does with relational tables.
Examples speak louder than words, so here is my theoretical model of an
RSS2.0 document, in python classes:
class RSS2( XMLModel ):
class XMLAttrs:
_tagname = 'rss'
version = '2.0'
class channel( XMLNode ):
title = XMLString()
description = XMLString()
link = XMLString()
lastBuildDate = XMLDate( format = "%a, %d %b %Y %H:%M:%S EST" )
generator = XMLString()
docs = XMLString()
class item( XMLNodeList ):
title = XMLString()
link = XMLString()
description = XMLString()
category = XMLList( type = XMLString() )
pubDate = XMLDate( format = "%a, %d %b %Y %H:%M:%S EST" )
To me, this is expressive, simple, and elegant. There is even a
possibility if removing a lot of those class names (I'm sure
XMLString(), could just be a str(), etc) but there are some functional
concerns that I think that having these helper classes may deal with.
Look at XMLList for example, it defines a time for each item. Having
said that, these 'value' classes, all would inherit from XMLValue; but
that is an implementation detail, this is just an example.
Here is an example of usage:
feed = new rss()
feed.channel.title = 'foo'
feed.channel.description = 'bar'
feed.channel.link = 'http://foo/bar'
feed.channel.lastBuildDate = datetime.now()
feed.channel.generator = 'XML Object'
feed.channel.docs = 'http:/foo/bar/docs'
feed.channel.item[0].title = 'foo'
feed.channel.item[0].link = 'http://foo/bar/1'
feed.channel.item[0].description = 'blah blah blah.'
feed.channel.item[0].pubDate = datetime.now()
feed.channel.item[0].category = ['foo', 'bar']
## or ##
item = feed.channel.item.new() ## or possibly: feed.channel.item()
item.title = 'foo'
item.link = 'http://foo/bar/1'
item.description = 'blah blah blah.'
item.pubDate = datetime.now()
item.category = ['foo', 'bar']
I'll probably go about trying to write this reguardless, but given some
positive feedback from the list, I may be more motivated. And I am
wondering if this would be a welcome addition to turbogears.
P.S. suggestions are *always* welcome
Sean
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---