from lxml import etree
xml_data = '''
<root><element attribute="value1">Text 1</element><element attribute="value2">Text 2</element><element attribute="value3">Text 3</element>
</root>
''' etree = etree. fromstring( xml_data) etree = etree. HTML( html_data)
[ 'Text 1' ] etree. xpath( '//element[@attribute="value1"]/text()' ) etree. xpath( '//element/text()' ) [ 0 ] etree. xpath( './element/text()' ) [ 0 ] etree. xpath( '/root/element/text()' ) [ 0 ] etree. xpath( '/root/element[1]/text()' ) etree. xpath( '/root/element[position()=1]/text()' ) etree. xpath( '/root/element[position()=1]/..' ) [ 0 ] . tag
etree. xpath( '//element[text()="Text 3"]/..' ) [ 0 ] . tag etree. xpath( '/root/element[position()=1]/text()/..' ) [ 0 ] . tag etree. xpath( '//element/text()' )
etree. xpath( './element/text()' )
etree. xpath( '/root/element/text()' ) [ 'Text 1' , 'Text 2' , 'Text 3' ]