[lxml-dev] prefix mappings
Stefan Behnel
stefan_ml at behnel.de
Sat Oct 6 19:33:07 CEST 2007
FnH wrote:
> I would like to generate the following serialization:
>
> <a xmls="foo">
> <b xmls="bar"/>
> </a>
[...]
> In order to solve this I think it would be a good idea to allow (or take
> into account) prefix mappings on non root nodes as well. The output I'd
> like could then be achieved by the following code snippet:
>
> a = Element("{foo}a", nsmap={None:"foo"})
> a.append(Element("{bar}b", nsmap={None:"bar"}))
>>> from lxml.etree import Element, tostring
>>> a = Element("{foo}a", nsmap={None:"foo"})
>>> a.append(Element("{bar}b", nsmap={None:"bar"}))
>>> print tostring(a, pretty_print=True)
<a xmlns="foo">
<b xmlns="bar"/>
</a>
This is on lxml 2.0 alpha, lxml 1.3 should work alike.
Stefan
More information about the lxml-dev
mailing list