I am trying to compare 2 XML files using the RecursiveElementNameAndTextQualifier() qualifier.
Changing the order of some entities may cause XMLUnit to pass on some cases and fail on other cases.
My XML file looks like this, and I'm comparing it to a similar copy which a simple swapping of some attributes locations.
Unfortunately your case is already more complex than RecursiveElementNameAndTextQualifier is able to work with. It really only works if there only is a single child with text content.
You need it to swap the two ent elements which it cannot do because there are two children with nested text inside them. So it your ent elements are picked in order and RecursiveElementNameAndTextQualifier would only work to re-order you value elements.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am trying to compare 2 XML files using the RecursiveElementNameAndTextQualifier() qualifier.
Changing the order of some entities may cause XMLUnit to pass on some cases and fail on other cases.
My XML file looks like this, and I'm comparing it to a similar copy which a simple swapping of some attributes locations.
<root>
<ent>
<value>
<int>1</int>
</value>
<value>
<int>2</int>
</value>
</ent>
<ent>
<value>
<int>3</int>
</value>
<value>
<int>4</int>
</value>
</ent>
</root>
When swapping int: 1 with int:2 , at the copy of the XML file, the test fails. But when swapping int:4 with int:3 it keeps the test passing.
Here is my testing code:
public void testRecursiveElement() throws Exception {
InputSource xml1 = new InputSource("xml1.xml");
InputSource xml2 = new InputSource("xml2.xml");
Diff myDiff = new Diff(xml1, xml2);
myDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier() );
assertXMLEqual("Not similar", myDiff, true);
}
Can you advice what is the problem , and how can I cause the diff operation to ignore swapping of the first set of entities ?
I've created unit tests from your description (see http://xmlunit.svn.sourceforge.net/viewvc/xmlunit?view=rev&revision=287 ) and both pass. There must be more differences in your document than I can gather from your description.
Thanks for your quick reply and the effort to put it into a unit test.
It seems the problem only exists with my external XML files.
Anyway it was solved using XMLUnit.setIgnoreWhitespace(true).
Thanks.
I would expect this test case to pass, but it fails. Is this a bug?
Unfortunately your case is already more complex than RecursiveElementNameAndTextQualifier is able to work with. It really only works if there only is a single child with text content.
You need it to swap the two ent elements which it cannot do because there are two children with nested text inside them. So it your ent elements are picked in order and RecursiveElementNameAndTextQualifier would only work to re-order you value elements.