ElementTree: namespace declaration in each element?

Fredrik Lundh fredrik at pythonware.com
Sun Nov 19 13:53:56 CET 2006

cyberco wrote:

> Unfortunately the client that needs to consume this XML can't handle
> the 'ns0:' part of each tag.

 > Is there a way to output XML similar to the input?

written by a "it's the bytes, not the data" guy, obviously ;-)

the standard serializer in 1.2 doesn't support default namespaces, so 
the quickest way to do this is to loop over all tags (use getiterator), 
strip off the "{http://xspf.org/ns/0/}" prefix, add an xmlns attribute 
to the root (if necessary), and write it out.


More information about the Python-list mailing list