file 1:
<xmlsource>
<sections>
<section>
<name>section 1</name>
<path>path to section 1</path>
</section>
</sections>
<items>
<item>
<name>item 1</name>
<path>path to item 1</path>
</item>
<item>
<name>item 2</name>
<path>path to item 2</path>
</item>
</items>
<forms>
<form>
<name>form 1</name>
<path>path to form 1</path>
</form>
</forms>
</xmlsource>
file 2:
<item>
<name>item 3</name>
<path>path to item 3</path>
</item>
<item>
<name>item 4</name>
<path>path to item 4</path>
</item>
How to merge/append file 2 into file 1 as follow (using Python):
<xmlsource>
<sections>
<section>
<name>section 1</name>
<path>path to section 1</path>
</section>
</sections>
<items>
<item>
<name>item 1</name>
<path>path to item 1</path>
</item>
<item>
<name>item 2</name>
<path>path to item 2</path>
</item>
<item>
<name>item 3</name>
<path>path to item 3</path>
</item>
<item>
<name>item 4</name>
<path>path to item 4</path>
</item>
</items>
<forms>
<form>
<name>form 1</name>
<path>path to form 1</path>
</form>
</forms>
</xmlsource>
a. The order of item 1 - item 4 are not important as long as they are in the same group
<items>
......
</items>
b. After merging/appending, the tabs in new file must match/be the same.
Thanks a bunch.
____________________________
I've saved file1 as sample1.xml, file2 as sample2.xml, and the below python code as combinexml.py, and saved all of them in C:\Users\BB\Desktop\CombineXML\ then run them using IDLE. Here what I got, please help
Traceback (most recent call last):
File "C:\Users\BB\Desktop\CombineXML\combinexml.py", line 46, in <module>
r = XMLCombiner(('sample1.xml', 'sample2.xml')).combine()
File "C:\Users\BB\Desktop\CombineXML\combinexml.py", line 7, in __init__
self.roots = [et.parse(f).getroot() for f in filenames]
File "C:\Python27\lib\xml\etree\ElementTree.py", line 1182, in parse
tree.parse(source, parser)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 656, in parse
parser.feed(data)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 1642, in feed self._raiseerror(v)
File "C:\Python27\lib\xml\etree\ElementTree.py", line 1506, in _raiseerror
raise err
ParseError: junk after document element: line 5, column 8
If this code works, what is the name and location of combined xml? Or either file1 or file2 will have the merged files and no new xml file created? Thank you.