Why etree.find doesn't find the element for the provided example



Lets suppose it has this:



xml_as_str = '''
<v1:Header>
<v2:Person>Foo Bar</v2:Person>
<v2:Email>foo@bar.com</v2:Email>
</v1:Header>
'''

from lxml import etree
tree = etree.fromstring(xml_as_str, etree.XMLParser(recover=True))


How could it get the value of certain tag, e.g "Foo Bar" for v2:Person ?


I've tried this:



>> tree.find('.//v2:Person')
>> tree.find('.//{Person}v2')


in order to get the element and then .text, but .find doesn't find the element, why?.


No comments:

Post a Comment