<p>I need to get a list of attribute values from child elements in Python.</p>

<p>It's easiest to explain with an example.</p>

<p>Given some XML like this:</p>

<pre><code>&lt;elements&gt;
    &lt;parent name="CategoryA"&gt;
        &lt;child value="a1"/&gt;
        &lt;child value="a2"/&gt;
        &lt;child value="a3"/&gt;
    &lt;/parent&gt;
    &lt;parent name="CategoryB"&gt;
        &lt;child value="b1"/&gt;
        &lt;child value="b2"/&gt;
        &lt;child value="b3"/&gt;
    &lt;/parent&gt;
&lt;/elements&gt;
</code></pre>

<p>I want to be able to do something like:</p>



<pre class="lang-python prettyprint-override"><code>&gt;&gt;&gt; getValues("CategoryA")
['a1', 'a2', 'a3']
&gt;&gt;&gt; getValues("CategoryB")
['b1', 'b2', 'b3']
</code></pre>

<p>It looks like a job for XPath but I'm open to all recommendations. I'd also like to hear about your favourite Python XML libraries.</p>

I must admit I'm a fan of
xmltramp
due to its ease of use.
Accessing the above becomes:
```
```
import xmltramp

  values = xmltramp.parse('''...''')

  def getValues( values, category ):
    cat = [ parent for parent in values['parent':] if parent(name) == category ]
    cat_values = [ child(value) for child in parent['child':] for parent in cat ]
    return cat_values

  getValues( values, "CategoryA" )
  getValues( values, "CategoryB" )
```
```