I\'m trying to use Python 2.7\'s ElementTree library to parse an XML file, then replace specific element attributes with test data, then save this as a unique X
For this kind of work, I always recommend BeautifulSoup because it has a really easy to learn API:
from BeautifulSoup import BeautifulStoneSoup as Soup
xml = """
"""
soup = Soup(xml)
rpt_side = soup.trdcaptrpt.rptside
rpt_side['txt1'] = 'Updated'
rpt_side.pty['id'] = 'Updated'
print soup
Example output:
Edit: With xml.etree.ElementTree you could use the following script:
from xml.etree import ElementTree as etree
xml = """
"""
root = etree.fromstring(xml)
rpt_side = root.find('RptSide')
rpt_side.set('Txt1', 'Updated')
pty = rpt_side.find('Pty')
pty.set('ID', 'Updated')
print etree.tostring(root)
Example output: