XML parsing per record
Willem Ligtenberg
WLigtenberg at gmail.com
Fri Apr 22 09:56:29 EDT 2005
As you can read in the other post of mine, my problem was with the
iterating through the list. didn't know that you should do. e.text. I did
only print e, not print e.text
Did read documentation, but must admit not everything.
Anyway, thank you very much!
On Fri, 22 Apr 2005 15:47:08 +0200, Fredrik Lundh wrote:
> Willem Ligtenberg wrote:
>
>> As I'm trying to write the code using cElementTree.
>> I stumble across one problem. Sometimes there are multiple values to
>> retrieve from one record for the same element. Like this:
>> <Prot-ref_name_E>ATP-binding cassette, subfamily G, member 1</Prot-ref_name_E>
>> <Prot-ref_name_E>ATP-binding cassette 8</Prot-ref_name_E>
>>
>> How do you get not only the first, but the rest as well, so that I can
>> store it in a list.
>
> findall returns a list of matching elements. if "elem" is the paretnt element,
> this gives you a list of the text inside all Prot-ref_name_E child elements:
>
> [e.text for e in elem.findall("Prot-ref_name_E")]
>
> (you have read the elementtree documentation, I hope?)
>
> </F>
More information about the Python-list
mailing list