[Twisted-web] Best way to serve up XML
Maarten ter Huurne
maarten at treewalker.org
Mon Jun 25 17:06:41 EDT 2007
On Monday 25 June 2007, Nicholas Milkovits wrote:
> I am working on my first twisted app which is a set of restful services
> that return xml to the consumers. When it comes to generating the XML it
> seems like there are a lot of solutions (i.e. building it manually using
> xml.dom.minidom, woven, nevow + stan, sux, microdom). I wanted to get an
> idea of what other twisted users think
> 1) is the most maintainable approach
I would avoid anything that uses the DOM API, because it is very clumsy. You
could use elementtree instead, which is bundled with Python from version 2.5
onwards.
For my work project, I wrote something like Nevow's Stan, that uses nested
Python expressions to build XML. It can use generators to create child nodes.
The resulting code is quite readable, because the Python code structure
matches the XML structure.
Probably it would be useful to write the same small example program using all
the APIs you're seriously considering and see how long and how readable the
resulting code is.
> 2) what method has the most stable supporting libs and
elementtree is part of the Python library now, so it's likely to be around for
a long time and not change a lot. Woven is no longer maintained, because
Nevow replaced it. Nevow is popular, so it's also likely to be around for a
long time, but it does change its APIs every now and then, as far as I know.
> 3) is the fastest.
The documents I generate are pretty small, so I haven't done much
benchmarking.
One thing you should avoid is repeatedly appending to a string. Instead, you
can put string fragments in a list and join that at the end, or use StringIO.
Bye,
Maarten
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20070625/7e167943/attachment.pgp
More information about the Twisted-web
mailing list