XMLMerge: merge XML documents

GeoNetwork TV at your service

XMLMerge

XMLMerge is a utility to merge XML documents. It has advanced configuration options where you can set exactly how you want the merge to be executed. See this excellent article to read about its capabilities.

XMLMerge is part of EL4J. EL4J is described as «the Extension Library for the J2EE, adds incremental improvements to the Spring Java framework. Features include: simplified POJO remoting (including support for SOAP and EJB), module abstraction, daemon manager, exception handling framework.». It is distributed under an Open Source LGPL license.

not a stand-alone library

One drawback to EL4J's XMLMerge is that it apparently is not distributed as a single, stand-alone JAR file that you can just stick into your application and use right away. Although there is a stand-alone web application, we've found it not completely trivial to just isolate the XMLMerge core code from it for use in a different application.

namespace support

We have also found that the XMLMerge code as distributed with EL4J lacks support for namespaces. If you want to merge a document that has, for example, a namespace declaration like xmlns:xxx="http://somenamespace" with another document that contains a declaration xmlns:yyy="http://somenamespace", you'd wish the XML merge to recognize that elements <xxx:something/> and <yyy:something/> really are the same element in the same namespace.

our distribution

We at GeoNetwork TV have added support for namespaces to XMLMerge and re-packaged it into a single jar file, without any dependencies on logging frameworks, on Spring or anything, that you can simply include for use in your own application. It only depends on dtdparser-1.21, jaxen-1.1.1 and jdom. An example of how you'd use it in your code is:

import ch.elca.el4j.services.xmlmerge.*;

XmlMerge xmlMerge = new DefaultXmlMerge();
String xmlDocument1 = "< ..your XML document 1.. >";
String xmlDocument2 = "< ..your XML document 2.. >";
String[] toMerge = { xmlDocument1, xmlDocument2 };
String mergedDocument = xmlMerge.merge(toMerge);

Our distribution is based on EL4J 1.7, distributed on SourceForge.

You can download a ready-made jar, compiled with JDK 1.5, or you can download the full sources.

You can see the original license terms (which we have not modified) here.