I am trying to use the Python 2.7 library ElementTreeto parse an XML file, then replace certain element attributes with test data, and then save it as a unique XML file.
My idea for the solution was to (1) get new data from the CSV file by reading the file into a line, (2) cut the line according to certain separator marks, (3) add to the list and then (4) use ElementTreeto update / Removing / replacing an attribute with a specific value from the list.
I looked in the documentation ElementTreeand saw the functions clear()and remove(), but I have no idea about the syntax for their adequate use.
The following is an example of an XML code to change - attributes with XXXXXneed to be replaced / updated:
<TrdCaptRpt RptID="10000001" TransTyp="0">
<RptSide Side="1" Txt1="XXXXX">
<Pty ID="XXXXX" R="1"/>
</RptSide>
</TrdCaptRpt>
The expected result will be, for example:
<TrdCaptRpt RptID="10000001" TransTyp="0">
<RptSide Side="1" Txt1="12345">
<Pty ID="ABCDE" R="1"/>
</RptSide>
</TrdCaptRpt>
How to use commands etreeto change the basic XML for updating using an element from the list []?
source
share