By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,270 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,270 IT Pros & Developers. It's quick & easy.

Removing NS in ElementTree

P: n/a
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


{http://uniprot.org/uniprot}accession
Q9JJE1
{http://uniprot.org/uniprot}organism
{http://uniprot.org/uniprot}dbReference
None
{http://uniprot.org/uniprot}sequence

MPKKKPTPIQLNPAPDGSAVNGTSSAETNLEALQKKLEELELDEQQRKRL
EAFLTQKQKVGELKDDDFEKISELGAGNGGVVFKVSHKPSGLVMARKLIH
LEIKPAIRNQIIRELQVLHECNSPYIVGFYGAFYSDGEISICMEHMDGGS
LDQVLKKAGRIPEQILGKVSIAVIKGLTYLREKHKIMHRDVKPSNILV

--
Sebastián Bassi (セバスティアン)
Diplomado en Ciencia y Tecnolog*a.
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
Club de la razón (www.clubdelarazon.org)
May 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Sebastian Bassi wrote:
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.
for el in root.getiterator():
if el.tag[0] == '{':
el.tag = el.tag.split('}', 1)[1]
That should do the job.

Stefan
May 26 '07 #2

P: n/a
"Sebastian Bassi" <sb****@clubdelarazon.orgwrites:
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
May 26 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.