Duncan Krebs
Duncan Krebs

Reputation: 3502

Merging XML Web Content Files

I'm in a unique position and am doing a merge of a bunch of xml content files into client specific svn branches and the issue is I can't just copy/paste over because that client has different translations and other labels defined. Trying to do this through svn merge is daunting and its like 50 files and many clients inolved. So the question I have how would one go about writing an eclipse plugin or even a java program that takes two xml files a source, target. All elements not in target that are in source add and existing elements in target with differnet labels do not change. Could I write this pretty quickly? What parser would I want to use, what tools would someone use to make this happen quickly. I can write the plugin fast the actual code for doing the comparison I need some input on. - Duncan

Upvotes: 0

Views: 96

Answers (1)

chad
chad

Reputation: 7537

XSLT is a very useful tool for this. It is made specifically for the purpose of transforming one XML document, or any subvariant such as HTML, into another. This seems to be specifically what you are doing.

Using XSLT, you define the rules for how you want your XML to be transformed in an XSL file; this XSL file consists of simple logic for specifying the parts of the XML you want to change, and also specifying how to change them. Next, you feed both your XSL rules and your XML source document, and it spits out the new XML result.

The good thing about using XSLT is that you can tweak it and run it again. And you can run it on batches of source XML files. Note, it's also nice that you can use it from many contexts. You can execute it as a command line tool to which you hand the parameters pointing to your XML source and XSL rules, and you can also use it from within Java code. It's quite flexible.

The only thing in your use case that I've not done before, with XSLT, is examing two source files at once. But this question disucusses just such a thing.

Upvotes: 1

Related Questions