xml tree writing with ElementTree; prepends elements with ns0

Alain Ketterlin alain at dpt-info.u-strasbg.fr
Tue Oct 11 05:40:48 EDT 2011


"Alex van der Spek" <alex.vanderspek at tno.nl> writes:

> When reading a tree and writing it back to a new file all the elements are 
> prepended with the string ns0:

That's a namespace prefix.

>
> Why is it prepended and how can I suppress this?

See http://effbot.org/zone/element-namespaces.htm

I'm not sure you can define the default namespace (i.e., avoid prefixes
on element names). However, any conformant XML processor should have no
problem with the output of ElementTree.

If you're actually producing HTML, then you should say so when calling
tostring(), by giving the appropriate value to the method argument.

-- Alain.



More information about the Python-list mailing list