[Python-Dev] Elementtree and Namespaces in 2.5

"Martin v. Löwis" martin at v.loewis.de
Fri Aug 11 21:35:52 CEST 2006


Chris S schrieb:
> I'm happy to see Elementtree being considered for inclusion with 2.5.
> However, before committing to this decision, there's an issue
> regarding it's namespace parsing that should be addressed. Although
> Elmenttree is in most respects an excellent XML parser, a huge gotcha
> that often makes Elementtree unsuitable for many applications lies in
> the way it arbitrarily renames namespaces.

Terminology alert: it doesn't rename namespaces. It renames namespace
prefixes. The namespaces stay unmodified.

> functionality (http://groups.google.com/group/comp.lang.python/browse_thread/thread/31b2e9f4a8f7338c/363f46513fb8de04?&rnum=3&hl=en)
> and while most users and the w3 spec
> (http://www.w3.org/TR/2001/REC-xml-c14n-20010315#NoNSPrefixRewriting)
> agree this feature is actually a bug, Fredrik Lundh has refused to fix
> this problem.

You are misunderstanding. The "w3 spec" does not say it is a bug; you
are looking at the wrong spec. The right spec to look at is

http://www.w3.org/TR/REC-xml-names/

You are looking at a resolution of an issue in the spec of
Canonical XML (i.e. not even the actual spec, just the resolution
of an issue).

Now, C14N specifies that the canonical form of an XML document has
the same namespace prefixes as the original document. So ElementTree
does not implement C14N for that reason, but I guess there are many
more reasons why ElementTree is not a C14N implementation. For example,
it puts the attributes before the namespace attributes, when C14N
says it should be the other way 'round.

> Of course, this is his right. Unfortunately,
> Elementtree's design makes a work-around rather awkward. Therefore, we
> might want to rethink inclusion of Elementtree in the stdlib

That is not enough reason. Yes, it makes certain applications
impossible, e.g. when namespace prefixes are inside attribute
values. It just means you can't use it for that application,
then. XML has many other applications, and so does ElementTree.

> or at
> least patch the stdlib's version of Elementtree to produce an output
> more in line with the w3 standard.

That is out of the question. It was agreed that ElementTree is added
to the standard library only if Fredrik Lundh gets veto rights on
all changes.

Regards,
Martin


More information about the Python-Dev mailing list