Ignoring XML Namespaces with cElementTree

dmtr dchichkov at gmail.com
Thu Apr 29 22:57:33 EDT 2010


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 (first cElementTree
adds them, then I have to remove them in python). Is there any way to
tell cElementTree not to mess with my tags? I need that in the
standard python distribution, not my custom cElementTree build...



More information about the Python-list mailing list