PyXML difficulties

Paul Boddie paul at
Fri May 22 00:06:45 CEST 2009

On 21 Mai, 22:58, emperorcezar <emperorce... at> wrote:
> I'm new to using the xml libs. I'm trying to create xml pragmatically,
> but I'm finding an issue. I have two elements I'm creating using
> createElementNS two elements (soap:Envelope and context). Each having
> a different namespace. When I print the created xml, the namespace
> attribute gets moved from the context element to the envelope element.
> Is there a reason for this, and how can I get it to not do that?

Having the default namespace declared on an ancestor of the context
element is completely valid in this case, since the soap:Envelope
element is associated with a different namespace. You could see what
happens if you serialise the document using a different library
function or document/node method, however.

> Code:
>     from xml.dom import implementation
>     from xml.dom.ext import PrettyPrint
>     namespace = ''
>     # create XML DOM document
>     doc = implementation.createDocument(None, '', None)


Note that according to the specifications, the element name should be
None (null) for this kind of createDocument invocation. See here for


More information about the Python-list mailing list