New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comparing nodes with checkForSimilar and checkForIdentical #160
Comments
I'm not sure I understand what you see and what you'd like to see. Without running code the behavior I would expect from your configuration is you get a "different" result because the order of If you still want to ignore the difference of order of the From your description it seems you are not getting |
I would like to ignore the order of 'Person' elements but I dont want to ignore the order of its child nodes. |
and with the change above you get differences for both or just the persons? |
This is what I get: I think that means I get differences for persons (which I dont want) and none for its children (which I would like to catch). |
To me it looks as if you now get all the differences for the children of
|
If you want to keep the differences for Very raw something like public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) {
if (comparison.getType() == ComparisonType.CHILD_NODELIST_SEQUENCE
&& ("person".equals(comparison.getControlDetals().getTarget().getParentNode().getLocalName())
|| "person".equals(comparison.getControlDetals().getTarget().getParentNode().getNodeName()))) {
return ComparisonResult.DIFFERENT;
}
return outcome;
} The The idea is to only upgrade the differences if the parent of the compared nodes is a Oh, and you'd still need to chain it behind |
How can this be? I changed my String xmls to these:
I use this again:
This is what I get:
The order in person's children is the same in both xmls so I would expect to find no differences at all. |
your |
So I guess this snippet catches both person's and its children differences. How can I make it to catch only its children ? |
see my example code above. |
So If I get this correctly, the idea is to implement a custom differenceEvaluator and then use it like this:
EDIT: |
You should place your Whether or not the setup ignores person's order but not its children depends on your |
sorry for editing the last post three times. This is what I meant "You should place your CustomDifferenceEvaluator at the end or the upgradeDifferencesToDifferent will overrule it again." |
my example from above would replace By default you'd get In you setup you'd upgrade all differences for swapped nodes and then use |
I get it now. I can't thank you enough. :) On to implement the customDifferenceEvaluator and I will report back :) |
🤞 |
So I implemented the customDifferenceEvaluator as in your example above but It doesnt spot the diffs about person's children order.
It doesnt find any diff at all. |
First of all, put your evaluator after When you say "doesnt find any diff at all" does that mean "no differences at all" or "no differences that are DIFFERENT but some that are SIMILAR"? |
Oh silly me, now it does find the person's children diffs and ignores the persons order. Once again you have been of great help good sir. |
you're welcome. |
Hello again,
Let's say I have these strings:
String xml1 ="<persons><person><Id>1</Id><name><firstName>George</firstName><lastName>White</lastName></name></person><person><Id>2</Id><name><firstName>John</firstName><lastName>Black</lastName></name></person></persons>";
String xml2 ="<persons><person><Id>2</Id><name><firstName>John</firstName><lastName>Black</lastName></name></person><person><name><firstName>George</firstName><lastName>White</lastName></name><Id>1</Id></person></persons>";
I don't mind about the order of 'person' elements but I do mind about the order of the child nodes of 'person' element like the 'name' element that comes before the 'Id' element in the xml2 string.
I figured I would use this:
but it just overrides the difference outcome of comparison of 'person' nodes not its children.
What am I missing here?
The text was updated successfully, but these errors were encountered: