XML::Merge is a Perl module that can merge XML documents.
This documentation refers to version 1.2.565EgGd of XML::Merge, which was released on Sun Jun 5 14:42:16:39 2005.
# create new XML::Merge object from MainFile.xml
my $merge_obj = XML::Merge->new('filename' => 'MainFile.xml');
# Merge File2Add.xml into MainFile.xml
$merge_obj->merge( 'filename' => 'File2Add.xml');
# Tidy up the indenting that resulted from the merge
# Write out changes back to MainFile.xml
This module inherits from XML::Tidy which in turn inherits from XML::XPath. This ensures that Merge objects' indenting can be tidied up after any merge operation since such modification usually spells the ruination of indentation. Polymorphism allows Merge objects to be utilized as normal XML::XPath objects as well.
The merging behavior is setup to combine separate XML documents according to certain rules && configurable options. If both documents have root nodes which are elements of the same name, the documents are merged directly. Otherwise, one is merged as a child of the other. An optional XPath location can be specified as the place to perform the merge. If no location is specified, the merge is attempted at the first matching element or is appended as the new last child of the other root if no match is found.