Merging of two XML documents
-
Although there does not seem to be too much traffic in here I'll give it a try anyway... I would like to be able to merge two XML documents, in such a manner that one will override the other. I.e., there will be a "global" XML file that contains some generic data, and then a "local" XML file that contains data that overrides data found in the global file. The local file does not have to contain the exact same number of nodes as the global one, i.e. it may only contain the nodes that we are interested in overriding. You may ask yourself "how can this be helpful?", one example could be a global file that contains various settings that are used in an application, including text strings that will be visible to the user, and then a local file that contains translation of these visible text strings to some other languge, but otherwise does not change the settings/data in any way. In this way it will be easy to localise this file (we might want to be able to translate into many languages) without having to maintain multiple copies of the settings file - one for each language. What I'm curious about is if there is a simple way to accomplish this through any known tools. The overhead should preferably be small, i.e. I don't want to be forced to install some massive Java libraries for this task alone :-). The code we're currently using to load/save XML files uses the Microsoft XML Parser so anything that's available through that tool is OK. I'm also willing to take a look at some .NET components if they do the job nicely, since this code will be used in an environment that ensures that the .NET framework has been installed. Mind you that there are some obstacles on the way, for instance if the files in question were to store a list of books (classic example) and we would like to display the name of each book in the correct language, then we could create two files: global.xml: Some book John Doe Another book Susanne Smith local.xml ( book names have been translated into Icelandic :-) ) : Einhver bók Einhver önnur bók where the local.xml file does not want to mess with the author names, and it must override the correct bookname based on the id's. Note that under some circumstances, xml nodes equivalent to the node might contain more attributes (not just the "id" attribute),
-
Although there does not seem to be too much traffic in here I'll give it a try anyway... I would like to be able to merge two XML documents, in such a manner that one will override the other. I.e., there will be a "global" XML file that contains some generic data, and then a "local" XML file that contains data that overrides data found in the global file. The local file does not have to contain the exact same number of nodes as the global one, i.e. it may only contain the nodes that we are interested in overriding. You may ask yourself "how can this be helpful?", one example could be a global file that contains various settings that are used in an application, including text strings that will be visible to the user, and then a local file that contains translation of these visible text strings to some other languge, but otherwise does not change the settings/data in any way. In this way it will be easy to localise this file (we might want to be able to translate into many languages) without having to maintain multiple copies of the settings file - one for each language. What I'm curious about is if there is a simple way to accomplish this through any known tools. The overhead should preferably be small, i.e. I don't want to be forced to install some massive Java libraries for this task alone :-). The code we're currently using to load/save XML files uses the Microsoft XML Parser so anything that's available through that tool is OK. I'm also willing to take a look at some .NET components if they do the job nicely, since this code will be used in an environment that ensures that the .NET framework has been installed. Mind you that there are some obstacles on the way, for instance if the files in question were to store a list of books (classic example) and we would like to display the name of each book in the correct language, then we could create two files: global.xml: Some book John Doe Another book Susanne Smith local.xml ( book names have been translated into Icelandic :-) ) : Einhver bók Einhver önnur bók where the local.xml file does not want to mess with the author names, and it must override the correct bookname based on the id's. Note that under some circumstances, xml nodes equivalent to the node might contain more attributes (not just the "id" attribute),
Yes it is possible, I have worked on many a project where xml files are merged. Unfortunatly I don't think there is any generic tool that will just do it for you, they way I have seen it done, is that the global xml file is loaded into the dom using MSXML, and the local file is loaded into a seperate dom. Then for each node in the local file, a select is run against the global dom, to see if that node already exists. If it does the value is either replaced if the node does not exist then it is added into the dom. All of this can be done using microsofts MSXML, just means writing some code yourself.
-
Yes it is possible, I have worked on many a project where xml files are merged. Unfortunatly I don't think there is any generic tool that will just do it for you, they way I have seen it done, is that the global xml file is loaded into the dom using MSXML, and the local file is loaded into a seperate dom. Then for each node in the local file, a select is run against the global dom, to see if that node already exists. If it does the value is either replaced if the node does not exist then it is added into the dom. All of this can be done using microsofts MSXML, just means writing some code yourself.
-
Thanks for your reply, writing code that uses the MSXML DOM is exactly what I have done, I was only curious if maybe I had reinvented the wheel :-)
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
The merging of two xml documents can be more easily and elegantly performed by using xslt. Here is a link that implements the same beautifully. http://www.informatik.hu-berlin.de/~obecker/XSLT/#merge Think of it as evolution in action