Removing NS in ElementTree

Rob Wolfe rw at smsnet.pl
Sat May 26 05:33:19 EDT 2007


"Sebastian Bassi" <sbassi at clubdelarazon.org> writes:

> I would like to remove the namespace information from my elements and
> have just the tag without this information. This
> "{http://uniprot.org/uniprot}" is preapended into all my output.
> I understand that the solution is related with "_namespace_map" but I
> don't know much more.
>
>
>>>> for x in eleroot[0]:
> 	print x.tag
> 	print x.text

Try this:

NS = "{http://uniprot.org/uniprot}"
for x in eleroot[0]:
    x.tag = x.tag[len(NS):]
    print x.tag

-- 
HTH,
Rob



More information about the Python-list mailing list