[Tutor] how to extract text by specifying an element using ElementTree
kent37 at tds.net
Tue Dec 20 18:58:40 CET 2005
ps python wrote:
> Dear Drs. Johnson and Yoo ,
> for the last 1 week I have been working on parsing
> the elements from a bunch of XML files following your
> from elementtree.ElementTree import ElementTree
>>>>mydata = ElementTree(file='00004.xml')
>>>>for process in
> print process.text
Looking at the data, neither <biological_process> nor <functions> elements directly
contain text, they have children that contain text. Try
to print the title.
>>>>for proc in mydata.findall('functions'):
> print proc
I think you want findall('//functions') to find <functions> at any depth in the tree.
If this doesn't work please show the results you get and tell us what you expect.
More information about the Tutor