This package is now available on the python cheeseshop:
http://www.python.org/pypi/xmlmodel
XMLModel allows you to expressively define an XML document, using
native python classes, you can then access the elements of the XML
through a tree of native python objects.
Expressive vs Imperative
Most XML generation libraries, have you do a lot of work to create an
XML document, i.e. DOM has you create a document object, then call
document.createNode(), manipulate that node, then do
document.appendChild( node ), this is functional, and flexible; it's
not readable. XMLModel allows you to define (read: "express") an XML
document in terms of a python class structure.
class book( XMLModel ):
class XMLAttrs:
generator = 'Book List 2.0'
class summary( XMLNode ):
title = XMLValue( 'default title' )
author = XMLValue( 'default author' )
description = XMLValue( 'default description' )
thebook = book()
print thebook
This will generate:
<?xml version="1.0"?>
<book generator="BookList 2.0">
<summary>
<title>default title</title>
<author>default author</author>
<description>default description</description>
</summary>
</book>
You can access the elements of the document as a normal object
structure:
thebook.XMLAttrs.generator = 'something else'
thebook.summary.title = 'Learning Python'
thebook.summary.author = 'Mark Lutz, David Ascher'
thebook.summary.description = 'Learning Python is an introduction
to the increasingly popular python programming language'
print thebook
Will output the following:
<?xml version="1.0"?>
<book generator="something else">
<summary>
<title>Learning Python</title>
<author>Mark Lutz, David Ascher</author>
<description>Learning Python is an introduction to the
increasingly popular python programming language</description>
</summary>
</book>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---