You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Stephen Cameron <st...@gmail.com> on 2014/05/05 05:59:07 UTC
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
AW: comparing two XML files
Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
> It is simply a comparison of values in the files not of the structure
> of the files.
If you could compare via xpath then you could write that directly in Camel:
from("direct:in")
.switch()
.when(xpath(...)).to(...)
> Now I want to pull in some more data to the route to
> allow me to decide what needs to pass on to the next Processor in the
> chain.
sounds like EIP "content enricher"
http://camel.apache.org/content-enricher.html
> Actually, I think I should read the Enterprise Integration Patterns book.
always good ;)
Jan
Re: comparing two XML files
Posted by Stephen Cameron <st...@gmail.com>.
Hi,
Thanks for your kind advice. But I have not explained the problem well
enough.
It is simply a comparison of values in the files not of the structure of
the files. A route seems a linear processing thing to my simple
understanding. Now I want to pull in some more data to the route to allow
me to decide what needs to pass on to the next Processor in the chain.
So I guess its both a transformation & a conditional splitting kind of
situation. I can write a custom Processor to do this. I just wondered if
there was an alternative Camel way to do it. Actually, I think I should
read the Enterprise Integration Patterns book. After a bit more reading it
is clear that I cannot get away with just asking for advice.
Thanks again.
On Mon, May 5, 2014 at 4:12 PM, Jan Matèrne (jhm) <ap...@materne.de> wrote:
> 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:steve.cameron.62@gmail.com]
> > Gesendet: Montag, 5. Mai 2014 05:59
> > An: users@camel.apache.org
> > 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
>
>
AW: comparing two XML files
Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
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:steve.cameron.62@gmail.com]
> Gesendet: Montag, 5. Mai 2014 05:59
> An: users@camel.apache.org
> 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