I'm trying to merge 2 xml documents using the XmlMerge 1.1.1 library and the result is VERY close to what I expect. The only issue I'm seeing is that text elements append the patch document's string to the original, which isn't my intention at all (I want to replace). For example:
When what I really want is this:
Is there a way to do this without privileges to modify the xml source? Thank you very much for your help!
Is there a particular reason you are using version 1.1.1? We recommend to update to the newest version (3.1) otherwise.
The xml merge tool supports your usecase. Here is a quick guide on how to make it do what you want (the code links are relevant for version 1.1.1, if you decide to upgrade, please exchange the tag in the links to el4j_3_1):
If you are using the command line interface, pass the following options along:
-config myconfigfile file1.xml file2.xml
contains the following:
There are other possible actions (= schemes on how to merge xml), look at the code here: https://el4j.svn.sourceforge.net/svnroot/el4j/tags/el4j_1_1_1/el4j/framework/modules/xml_merge/common/src/main/java/ch/elca/el4j/services/xmlmerge/action/StandardActions.java, and the containing folder.
For examples on how to change the action used depending on your location on the XML document, or to programatically configure the xml merge tool have a look at the test suite here: https://el4j.svn.sourceforge.net/svnroot/el4j/tags/el4j_1_1_1/el4j/framework/modules/xml_merge/common/src/test/java/ch/elca/el4j/tests/xmlmerge/DefaultMergeTest.java
If you have further questions, please don't hesitate to ask.
Thank you very much for your help. I'm actually using the XmlMerge library in my own open source project (http://www.romraider.com) and chose 1.1.1 because I couldn't find a standalone build of later versions and don't need the rest of the el4j functionality. I may look in to building a newer version but for the time being it looks like 1.1.1 will fill my needs.
I thought it might help me get a better understanding of the API if I looked through the command line documentation but the links aren't working. Is there another place I can read the documentation?
I did manage to find the documentation in a download archive. I'm using XPath and Properties. I've got the hang of it now but bad practice in the xml sources I'm merging has brought up one last problem. The names of elements that should be merged don't match. The rule is fairly simple but I'm having trouble finding a way do it it programatically.
<table name="Target Boost" rom>
<table name="Throttle" type="X Axis" elements="8" scaling="%" />
<table name="Engine Speed" type="Y Axis" elements="9" scaling="RPM" />
<table name="Target Boost" address="2a726">
<table name="X" address="2a714" elements="500"/>
<table name="Y" address="2a701" />
In the second file, the axis table names were replaced with a shortened version of the type attribute. The easiest way would be to add a new id attribute to each; if type='X Axis' or name='X', then id='x', and then match on id. Is there a way to do this?
Thanks again for the help!
Sorry about the links not working, I was about to fix that problem but was hindered because sourceforge was getting hacked (as you might have noticed by now ;)). This will be fixed as soon as SFTP uploads will be reenabled.
About your problem: I don't think there already is a solution ready to use yet. But I guess you could try to write a Matcher class yourself and use that to find out if two elements match. Maybe analogous to https://el4j.svn.sourceforge.net/svnroot/el4j/tags/el4j_1_1_1/el4j/framework/modules/xml_merge/common/src/main/java/ch/elca/el4j/services/xmlmerge/matcher/IdMatcher.java.
I hope I could help. Have fun!
My solution was to create an XSL transform to make attributes play more friendly with XmlMerge. Unfortunately, my source documents aren't ordered so I don't think XmlMerge is going to work for me. I appreciate your input though.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.