I have two XML files that I'd like to merge the data into the same structure as the example below. The actual files are larger and more complex so copying and pasting is not an efficient option.
Is there any way that this can be done quickly?
File1.xml:
<part1>
<g1> abc.
</g1></part1>
<part2>
<g2> def.
</g2></part2>
File2.xml:
<part1>
<g1> 123.
</g1></part1>
<part2>
<g2> 456.
</g2></part2>
Combined.xml
<part1>
<g1> abc. 123.
</g1></part1>
<part2>
<g2> def. 456.
</g2></part2>
Yes, there's loads of ways to 'merge' XML. But what you're going to need to do it is an XML parser, because XML is a structured data format.
Which one you use is very much a question of which language do you prefer?
Me? I like Perl and
XML::Twig
:This'll take your source text and turn it into:
But I'm sure there's better routes you can take, and other languages you can use.