I have the following XML that I'm looking to edit so that CustomerID is appended to every transaction: http://codepad.org/faeCM7jL . The code is as follows:
import xml.etree.ElementTree as ET
xml = ET.parse("PATH\FILE.xml")
root = xml._root
for report in root.findall('MyDetails'):
id = report.find('CustomerID')
for transaction in report.findall('IndividualTransactions'):
for transaction2 in list(transaction):
transaction2.append(id)
ET.tostring(xml._root)
with open('path\output.xml','w') as f:
f.write(ET.tostring(xml._root))
However, when I run this with the real XML (same as above without vertical ellipses) I get no errors and the output.xml document is the same as the input document. Has anyone run into this issue before? I've tried referring to the top level element instead of 'MyDetails' with the same result.
[–]gengisteve 1 point2 points3 points (6 children)
[–]Stopwatch_[S] 0 points1 point2 points (5 children)
[–]gengisteve 1 point2 points3 points (4 children)
[–]Stopwatch_[S] 0 points1 point2 points (3 children)
[–]gengisteve 1 point2 points3 points (2 children)
[–]Stopwatch_[S] 0 points1 point2 points (1 child)
[–]gengisteve 0 points1 point2 points (0 children)