擅长:python、mysql、java
<p>就我个人而言,我会使用lxml而不是原生python ETree代码。这样就可以使用XPath,这使得操作xml变得更加容易。你知道吗</p>
<p>例如,获取您请求的元素的代码是:</p>
<pre><code>param = root.xpath(/project[@name="proj1"]/design[@name="des2"]/param/Text()')
</code></pre>
<p>更新:看起来ETree支持完整XPath的一个子集,因此它可以满足@mgibsonbr指出的需求</p>