request for advice - possible ElementTree nexus

Fredrik Lundh fredrik at pythonware.com
Wed Jul 5 07:34:29 EDT 2006


mirandacascade at yahoo.com wrote:

> c) If I want to leave the xmlns information in the string that gets fed
> to ElementTree.XML, and I want to remove the {whatever} from the tag
> before building the data structure, what is the best way to find
> {whatever} from the tag property...is this another case where one
> should be using regular expressions?

if the "whatever" in {whatever} is known in advance, you can use the 
approach described here:

     http://effbot.org/zone/element-tidylib.htm#converting-xhtml-to-html

if the "whatever" is not known, you can do e.g.

     if elem.tag.startswith("{"):
         elem.tag = elem.tag.split("}")[1]

</F>




More information about the Python-list mailing list