For comparing XML I would google or have a look at XMLUnit [1].

AFAI understand Camel it reacts on one message. But you want to compare two 
files.
So the message could contain the content of both files.

from("direct:in")
    .bean(MyXmlDiff.class, "compare(${headers.XML_ONE}, ${headers.XML_TWO}")
    .to("velocity:...")
    .to("direct:out")

I assume that the content of both files is available via the two message 
headers XML_ONE and XML_TWO.

I use bean binding [3] for invoking my custom bean.
That uses XMLUnit for just doing the comparison
   public class MyXmlDiff {
       public String compare(String xml1, String xml2) {
           StringBuilder rv = new StringBuilder;
           Diff xmlunitDiff = new Diff(xml1, xml2);
           if (xmlunitDiff.similar()) {
               // use XMLUnit classes for getting the diffs and add
               // them to this return value.
               rv.add(...);   
           }
           // The return value of this method is the body
           // of the next Camel step.
           return rv.toSting();
       }
   }

Then use a template language for generating the final artifact.


Because I am not sure if headers are copied via the bean binding, maybe use 
message properties instead.


Jan


[1] http://xmlunit.sourceforge.net/
[2] https://camel.apache.org/bean-binding.html




> -----Ursprüngliche Nachricht-----
> Von: Stephen Cameron [mailto:[email protected]]
> Gesendet: Montag, 5. Mai 2014 05:59
> An: [email protected]
> Betreff: comparing two XML files
> 
> Hi,
> 
> I want to do a data processing task, that involves comparing the
> contents of two XML files. This is simply to match the equivalent
> record in the second for every record in the first, make a decision by
> comparing these matches, then generate a third file with the actions
> messages based on the the comparison result.
> 
> If there is no match made that is another message type that needs to be
> created.
> 
> I procedural code this is a inner and outer loop kind of situation. How
> can I set up the same thing in Camel. Or, should I write some custom
> code to do it?
> 
> Thanks for your advice, or pointing me in a good direction.
> 
> Steve Cameron

Reply via email to