-
Notifications
You must be signed in to change notification settings - Fork 73
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
Unable to ignore element order #44
Comments
In order to get a similar result XMLUnit must at least consider comparing the first object element of control to the second one in test. I.e. the Have you configured an From your example it is difficult to tell what would identify "matching" object elements. The textual content of the child with name |
My example was too simple. In fact, in my case, I am comparing two XML generated by java objects serialization. As I can serialize Set of objects, I want to compare them in the same way that would be done by a java equals on a set of objects. If I have the same set of objects, without regarding the order, I need to return that the XML are similar. => To identify the matching object element, we need to recursively check that all the fields under the tested element are in the control element, no matter the order. i.e. when we check if object1 from the tested xml is in the control xml, we will iterate on the objects of the control, and for each object check if all the subelements of the tested object are in the current control object. So I was thinking that you could provide a modifier on the DiffBuilder object to set a boolean "ignoreOrder" to do this. I did not find anything in the doc to easily do this. |
That's because it isn't easy :-) Not at all. What you want would boil down to trying to compare all possible pairs of child elements and then pick the permutation that caused the least amount of differences. I've already thought about adding an I'm sorry, there is no generic solution right now. |
Yes, according to my understanding of the mechanism of XMLUnit, you first need to find which control element must be compared to the testing one, but in my case we don't want to compare a specific node with another that was previously filtered by the ElementSelector. So we should have an ElementSelector that return a set of nodes (by default all the nodes with the same tag name, on the same level), and check if the tested element is in the set. Let me know if one day you find a way to achieve such a thing, and thank's for your help ! :) |
I've opened #45 for this.
means to compare the nodes recursively again, which may contain sets of nodes that need the same treatment somewhere down the tree, in the end. This is more complex in XML than one would hope for. In your case I'd probably rather deserialize the documents again and use Java to compare the sets. |
Yes I was thinking about this solution, but this is a pretty huge project with hundreds of classes and most of them do not override equals/hashcode. |
I'd like to close this issue - even if the answer to your question isn't the one you'd like to hear. Is this OK with you? |
No problem, thank's for your help ! |
hello,
I am using the version 2.0.0-alpha-03.
I want to compare two XML that contain the same data in a different order.
Example:
Test:
value1
value2
value3
value4
Control:
value3
value4
value1
value2
I have the same objects in my list of objects, therefore I expect to obtain a similar comparison result, as the order does not matter in my case.
My problem is that I can not find a way to achieve this result.
I always get this error: "Expected text value 'value3' but was 'value1'"
Is it possible to provide a way to easily ignore the order in such a case?
Thank's
The text was updated successfully, but these errors were encountered: