I have this xml file that has a lot of chemical groups and their properties. Here is a slice of the file:
<groups>
<group name='CH3'>
<mw>15.03502</mw>
<heatCapacity>
<a>19.5</a>
</heatCapacity>
</group>
<group name='CH2'>
<mw>14.02708</mw>
<heatCapacity>
<a>-0.909</a>
</heatCapacity>
</group>
<group name='COOH'>
<mw>45.02</mw>
<heatCapacity>
<a>-24.1</a>
</heatCapacity>
</heatCapacity>
</group>
<group name='OH'>
<mw>17.0073</mw>
<heatCapacity>
<a>25.7</a>
</heatCapacity>
</group>
<\groups>
In my python code that parses this file using ElementTree I have a list blocks=['CH3','CH2'] and I want to use this to find the two groups. I tried the following:
import elementtree.ElementTree as ET
document = ET.parse( 'groups.xml' )
blocks=['CH3','CH2']
for item in blocks:
group1 = document.find(item)
print group1
And all I get is 'None'. Can you please help me?
Many thanks
lxmlyou can just dodoc.xpath("//group[starts-with(@name,'CH')]"), but I don't think elementtree has proper xpath support to handle that expression.import xml.etree.ElementTree as ETas the import statement.