I have an xml file as below and I want to read data from my device and write the data into “value” column on certain name by using python script.
<TopoDefs>
<Device Name="SNB" LogicalType="CORE" IdCode="0x03886A21" Mask="0xf0000000">
<Variable name="A0" value="0x52001321" type="GREEN" />
<Variable name="A1" value="0x51001321" type="GREEN" />
<Variable name="A2" value="0x03001321" type="GREEN" />
<Variable name="A3" value="0x14001321" type="GREEN" />
<Variable name="B0" value="0x5A001321" type="BLUE" />
<Variable name="B1" value="0x51001321" type="BLUE" />
<Variable name="B2" value="0x04001321" type="BLUE" />
<Variable name="B3" value="0x05001321" type="BLUE" />
</Device>
</TopoDefs>
May I asks how to I point to the variable A0 to write a new data on “value” attribute?
What is the differences among find, findall, iterfind, itertext?
Using
lxml, that I argue is the best tool available for the task:Or you can loop through
Variablesand change all values as I understood you wanted: