-
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
Can't match 2 xml with different node order and element order in nodes #123
Comments
You are not telling XMLUnit which The correct solution really depends on what your real XML uses to identify the
should work. |
Thank you for your fast response and explanation. Your code works in this particular example. |
Technically one could just try all permutations and use the one "that works". There is no built-in solution that would do that, yet. This is what #45 is about. One thing to take note of is this is going to be very inefficient, even more so on big documents - which at the same time would be the documents that would benefit from such an approach the most. In the absence of a brute force try all paths approach XMLUnit needs you help. It cannot know what is expected to provide the "identifier" for any given XML element. This is why you'd need to spell out all the "identifying logic" explicitly right now. At least I don't see any middle ground between "try all" and "configure explicitly". I'd be happy if anybody can provide a better idea. |
If I may suggest a workaround for now, until #45 gets implemented. You could add a custom DifferenceEvaluator and then perform a simple-minded brute force check by comparing all parent nodes in the control tree against the nodes in the actual tree. Something like this did the trick for me:
And the comparison itself:
|
Thank you for sharing @Nihilum. This uses What is making #45 more complicated is that you want to take |
Thank you so much, @Nihilum. I tried your solution. The journey begins when you have situation like:
The main difference is that one Node doesn't have optional element2 and the order is mixed. I catch NPE in method constructParentNodesHierarchy, line Node localParentNode = node.getParentNode(); It can't get parent Node out of null :( |
Hi, I am trying to Compare Xmls using XMLUnit. I have 5 nodes in control Xml and I removed the node 3 in test Xml. The comparision results are happening differently like the node 3 in control Xml is compared with node4 in text Xml. Can any body suggest the correct code to compare the exact node. Here is my Java Code: import java.io.File; import org.xmlunit.builder.DiffBuilder; public class XMLDifference { Diff documentDiff = DiffBuilder.compare(control).ignoreWhitespace().ignoreComments().normalizeWhitespace().withTest(test).withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) .checkForSimilar().build(); int i = 0; Here are my Xmls. control XMl : Gambardella, Matthew <title>XML Developer's Guide</title> Computer 44.95 2000-10-01 An in-depth look at creating applications with XML. Ralls, Kim <title>Midnight Rain</title> Fantasy 5.95 2000-12-16 A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world. Corets, Eva <title>Maeve Ascendant</title> Fantasy 5.95 2000-11-17 After the collapse of a nanotechnology society in England, the young survivors lay the foundation for a new society. Corets, Eva <title>Oberon's Legacy</title> Fantasy 5.95 2001-03-10 In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant.Test Xml 👍 Gambardella, Matthew <title>XML Developer's Guide</title> Computer 44.95 2000-10-01 An in-depth look at creating applications with XML. Ralls, Kim <title>Midnight Rain</title> Fantasy 5.95 2000-12-16 A former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world. Corets, Eva <title>Oberon's Legacy</title> Fantasy 5.95 2001-03-10 In post-apocalypse England, the mysterious agent known only as Oberon helps to create a new life for the inhabitants of London. Sequel to Maeve Ascendant. Corets, Eva <title>The Sundered Grail</title> Fantasy 5.95 2001-09-10 The two daughters of Maeve, half-sisters, battle one another for control of England. Sequel to Oberon's Legacy.Result 👍
|
@mohannune your comment i not related to this issue, please create a new issue if you've got a new question. |
Hello!
I'm trying to match 2 xml responses, test and actual, with different node order and different element order in nodes.
Example:
Here is my code I'm trying to match with:
As a result I get many differences between two xml
Please tell me what I'm doing wrong.
The text was updated successfully, but these errors were encountered: