I'm using the cElementTree
module in Python to get the text child of an XML
tree, using the text
property. But it seems to work only for the immediate text children (see below).
$ python
...
>>> import xml.etree.cElementTree as ET
>>> root = ET.XML('<root><elm key="value">Some text</elm>More text</root>')
>>> root.text
>>> root = ET.XML('<root>Text 1<elm key="value">Text</elm>Text 2<elm2 />Text 3</root>')
>>> root.text
'Text 1'
>>>
Is it possible to retrieve all immediate text children of a given element (maybe as a list, i.e. ['More text']
and ['Text 1', 'Text 2', 'Text 3']
in the above examples) using the cElementTree
module?