Ignoring XML Namespaces with cElementTree

Stefan Behnel stefan_ml at behnel.de
Sat May 1 02:27:46 EDT 2010


dmtr, 30.04.2010 23:59:
>> I think that's your main mistake: don't remove them. Instead, use the fully
>> qualified names when comparing.
>
> Yes. That's what I'm forced to do. Pre-calculating tags like tagChild
> = "{%s}child" % uri and using them instead of "child".

Exactly. Keeps you from introducing typos in your code. And keeps you from 
having to deal with namespace-prefix mappings. Big features.


> As a result the
> code looks ugly and there is extra overhead concatenating/comparing
> these repeating and redundant prefixes.

The overhead is really small, though. In many cases, a pointer comparison 
will do.


> I don't understand why
> cElementTree forces users to do that. So far I couldn't find any way
> around that without rebuilding cElementTree from source.

Then don't do it.


> Apparently somebody hard-coded the namespace_separator parameter in
> the cElementTree.c (what a dumb thing to do!!!, it should have been a
> parameter in the cElementTree.XMLParser() arguments):
> ===========
> self->parser = EXPAT(ParserCreate_MM)(encoding,&memory_handler, "}");
> ===========
>
> Simply replacing "}" with NULL gives me desired tags without stinking
> URIs.

You should try to calm down and embrace this feature.

Stefan




More information about the Python-list mailing list