user2643864 user2643864 - 1 year ago 47
Python Question

A pythonic way to use Lxml to find all elements of a certain type

I'm not very good with Lxml but thought a few of you might know how one can quickly get through the following task. See below... Specifically, I need to parse the XML to get the value of the name attribute in all of the category elements. For example:

<category name="Test">
<category name="Acme">

So for the above case, the results would be the following category names as a result:


Answer Source
names = root_el.xpath('//category/@name')