How to find a tag with some value in python and lxml

vlissinger

New Member
I have an xml file with the following structure:\[code\]<main_tag> <first> <tag1>val1</tag1> <conf> <tag2>val2</tag2> <tag3>val3</tag3> <tag4>val4</tag4> </conf> </first> <second> <tag1>val2</tag1> <conf> <tag2>val6</tag2> <tag3>val7</tag3> <tag4>val8</tag4> </conf> </second></main_tag>\[/code\]I have to change the value of tag2. Possible values are stored in a dict:\[code\]{tag2values:[newvalue1, newvalue2]}\[/code\]If value of tag1 is val1, then we change tag2 value to newvalue1. If tag1 value is val2, then we change tag2 value to newvalue2.So the question is: is there a way to find an element in lxml matching its parent's value? Or to find an element by it's parent neighbour value?
 
Back
Top