[XML-SIG] Re: Generating XML from scratch
rsalz at datapower.com
Fri Feb 11 21:26:22 CET 2005
> OK, I'll bite. Which characteristics make DOM un-pythonic?
Quick reply, with some items off the top of my head.
XML says that the order of attributes and namespace nodes doesn't
matter, just the name and value. This maps naturally to Python
dictionary. On the other hand, the order of an element's children does
matter. This maps naturally to a Python list.
Starting from those two basic concepts, think about how simpler many
things become -- no addBefore, addAfter, etc, just standard Python list
slices. Much other stuff can be thrown out.
The element object should have a "resolve_qname" method which takes a
'foo:bar' qname and returns a (nsuri,localname) tuple. This removes the
need for many of the DOM get.../get...NS routines.
for k,v in curelt.attributes.items():
(ns,localname) = curelt.qname_resolve(k)
... now look at all attriubtes, by qname, ns, or localname
And so on.
>>If you are "just" generating XML, then you will probably go faster if
>>you use things that naturally fit into the python programming idioms.
Don't call complex API's. Instead set attributes on objects. That
seems to be how ElementTree and amara work, for example. But I think
that generating XML is not a very hard or interesting problem, and that
it is very application specific -- i..e, it depends too much on what the
local object that you are trying to serialize is. But I'm apparently in
a real minority here, so don't listen to me.:)
Rich Salz, Chief Security Architect
DataPower Technology http://www.datapower.com
XS40 XML Security Gateway http://www.datapower.com/products/xs40.html
XML Security Overview http://www.datapower.com/xmldev/xmlsecurity.html
More information about the XML-SIG