def bench_lxml_xpath_direct(root):
    name_list = root.xpath('book/author/name/text()')
print('Size of list = ' + str(len(name_list)))

def bench_lxml_xpath_loop(root):
    name_list = root.xpath('book/author/name')
result = []
for n in name_list:
    result.append(n.text)
print('Size of list = ' + str(len(name_list)))

def bench_lxml_getiterator(tree):
    result = []
for name in tree.getiterator('name'):
    result.append(name.text)
print('Size of list = ' + str(len(result)))

def bench_lxml_findall(tree):
    result = []
for name in tree.findall('//name'):
    result.append(name.text)
print('Size of list = ' + str(len(result)))
Fast python XML validator with XPath support