I have two xml files, where A references B. I would like a way to combine them into single xml file in Python.
FileA.xml
<FileAServices>
<Services ref="FileB.xml" xpath="Services"/>
</FileAServices>
FileB.xml
<Services>
<ThreadName>FileBTask</ChangeRequestName>
</Services>
Output
<FileAServices>
<Services>
<ThreadName>FileBTask</ThreadName>
</Services>
</FileAServices>
I've only gotten as far as below. I don't know how to assign the entire tree to elem.
import xml.etree.ElementTree as ET
base = ET.parse('FileA.xml')
ref = ET.parse('FileB.xml')
root = base.getroot()
subroot = ref.getroot()
for elem in root.iter('Services'):
elem.attrib = {}
for subelem in subroot.iter():
subdata = ET.SubElement(elem, subelem.text)
if subelem.attrib:
for k, v in subelem.attrib.items():
subdata.set(k, v)