I have an xml file as below and I want to read data from my device and write the data into “value” column 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>
I am completely a new learner of python scripting. How to parse the xml file and point to the attribute value to replaced by a new value that will changed all the time?
If i using getElementsByTagName and nodevalue, it would read all the string of the node, how do I limit by reading the value only and the other variables remain the same?
Here’s an example that iterates over all the Devices in the document, and all the Variables in a Device: