Parse all but a few nodes with certain attribute values



Using elementtree, is there a easy way to parse the entire xml document except those text that are on nodes that have some particular attribute value. As an example I would like to parse the file except for when attribute name="Liechtenstein"and when attribute month="08"



<data>
<country name="Liechtenstein">
<rank updated="yes">2</rank>
<language>english</language>
<currency>1.21$/kg</currency>
<gdppc month="06">141100</gdppc>
<gdpnp month="10">2.304e+0150</gdpnp>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank updated="yes">5</rank>
<language>english</language>
<currency>4.1$/kg</currency>
<gdppc month="05">59900</gdppc>
<gdpnp month="08">5.2e-015</gdpnp>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Lahore">
<rank updated="yes">8</rank>
<language>Pertr</language>
<currency>7.3$/kg</currency>
<gdppc month="010">34000</gdppc>
<gdpnp month="099">3.4e+015</gdpnp>
<neighbor name="Peru" direction="N"/>
</country>


Based on the above, I would like to return the following 5, english, 4.1$/kg, 59900, 8, Pertr, 7.3$/kg, 34000, 3.4e+015. I feel one can use iterparse but I do not know how to go about this. Thanks for the suggestions


No comments:

Post a Comment