updating XML attribute value in python



In the below XML, I want to parse it and update the value of "alcohol" to "yes" for all the attributes where age>21. I'm having a problem with it being a node buried inside other nodes. Could someone help me understand how to handle this?


Here's the XML again..



<root xmlns="XYZ" usingPalette="">

<grandParent hostName="XYZ">
<parent>
<child name="JohnsDad">
<grandChildren name="John" sex="male" age="22" alcohol="no"/>
</child>
<child name="PaulasDad">
<grandChildren name="Paula" sex="female" age="15" alcoho="no"/>
</child>
</parent>
</grandParent>
</root>


I tried find all and find method using this document here (http://ift.tt/1vO21Oh) but it didn't find it. For example, following code returns no results



for node in tree.findall('.//grandParent'):
print node

No comments:

Post a Comment