You could merge the files by hand or you could set up an merging functionality to do it automatically for you. With the little framework I present here, you can easily set up your own XML file merging. The framework is available under the EL4J project (http://EL4J.sf.net) as part of the xml merger module. It was contributed by Laurent Bovet (from outside of the EL4J core team), thanks.
Let's look at a simple example:
The following simple code implements this:
public String merge(String original, String patch) {
Configurer c = new PropertyXPathConfigurer("xpath.1=/root/d \n matcher.1=ID");
return new ConfigurableXmlMerge(c).merge(new String[]{original, patch} );
}
You may ask: what does it mean to merge XML documents? I think it is difficult to find a general answer to this question:
- Sometimes the second XML file should be able override tags of the first XML file
- What are the branches that should be merged? Just the same XML tags? Or does some attribute need to be equal?
- Sometimes some branches of the XML document may need to be left out
Please consult the detailed documentation or the samples of the xml merger in case you would like to know more.