XML parsing per record
Fredrik Lundh
fredrik at pythonware.com
Fri Apr 22 09:47:08 EDT 2005
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