Ignoring XML Namespaces with cElementTree

Stefan Behnel stefan_ml at behnel.de
Fri Apr 30 01:12:03 EDT 2010

dmtr, 30.04.2010 04:57:
> I'm referring to xmlns/URI prefixes. Here's a code example:
>   from xml.etree.cElementTree import iterparse
>   from cStringIO import StringIO
>   xml = """<root xmlns="http://www.very_long_url.com"><child/></
> root>"""
>   for event, elem in iterparse(StringIO(xml)): print event, elem
> The output is:
>   end<Element '{http://www.very_long_url.com}child' at 0xb7ddfa58>
>   end<Element '{http://www.very_long_url.com}root' at 0xb7ddfa40>
> I don't want these "{http://www.very_long_url.com}" in front of my
> tags.
> They create performance disaster on large files

I seriously doubt that they do.

> (first cElementTree
> adds them, then I have to remove them in python).

I think that's your main mistake: don't remove them. Instead, use the fully 
qualified names when comparing.


More information about the Python-list mailing list