user2643864 user2643864 - 3 months ago 9
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:

<categories>
<category name="Test">
<p>test_1</p>
</category>
<category name="Acme">
<p>acme_1</p>
</category>
</categories


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

Test
Acme

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