Dear group, In my XML file some attributes have text within an element. I want to get that text. How can I do that. I looked into ElementTree -bits and pieces: and there is a small function.
>>> def gettext(elem): ... text = elem.text or "" ... for e in elem: ... text += gettext(e) ... if e.tail: ... text += e.tail ... return text >>> for m in tree.findall('//{org:hprd:dtd:hprdr2}proteinInteractor'): ... k = gettext(m) ... print k ... >>> I got nothing out of it. I tried more preliminary way: >>> for m in tree.findall('//{org:hprd:dtd:hprdr2}proteinIn ... k = m.findtext('{org:hprd:dtd:hprdr2}secondaryRef' ... print k ... >>> for m in tree.findall('//{org:hprd:dtd:hprdr2}proteinIn ... print m ... >>> The part of the xml file is listd below. Could any one you help me please. I want to get : <proteinInteractor id="HISTONEH3"> id value: Thanks w <interactions> <entrySet xmlns="net:sf:psidev:mi" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="net:sf:psidev:mi http://psidev.sourceforge.net/mi/xml/src/MIF.xsd" level="1" version="1"> <entry> <source> <names> <shortLabel>HPRD</shortLabel> <fullName>Human Protein Reference Database</fullName> </names> <bibref> <xref> <primaryRef db="PubMed" id="14525934"/> <secondaryRef db="PubMed" id="14681466"/> </xref> </bibref> </source> <interactorList> <proteinInteractor id="HISTONEH3"> <names> <shortLabel>Histone H3</shortLabel> </names> <organism ncbiTaxId="9606"> <names> <shortLabel>Human</shortLabel> <fullName>Homo sapiens</fullName> </names> </organism> </proteinInteractor> <proteinInteractor id="ID_HPRD_00303"> <names> <shortLabel>Minichromosome maintenance protein 2</shortLabel> </names> <organism ncbiTaxId="10090"> <names> <shortLabel>Mouse</shortLabel> <fullName>Mus musculus</fullName> </names> </organism> </proteinInteractor> <proteinInteractor id="ID_HPRD_04072"> <names> <shortLabel>MCM3</shortLabel> </names> <organism ncbiTaxId="10090"> <names> <shortLabel>Mouse</shortLabel> <fullName>Mus musculus</fullName> </names> </organism> </proteinInteractor> <proteinInteractor id="ID_HPRD_09094"> <names> <shortLabel>MCM4</shortLabel> </names> <organism ncbiTaxId="10090"> <names> <shortLabel>Mouse</shortLabel> <fullName>Mus musculus</fullName> </names> </organism> </proteinInteractor> Send instant messages to your online friends http://in.messenger.yahoo.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor