views:

281

answers:

1

Hi,

I am trying to compare 2 XML files using XMLUnit 1.2. I am using the RecursiveElementNameAndTextQualifier() qualifier.

When changing the order of some entities order in my XML, it causes 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 with a simple location swapping of one peer of attributes.

<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 , in one of the XML files, the test fails. But when swapping int:4 with int:3 it keeps 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 why does XMLUnit detect a diff in the first case and not in the second case. Is there any solution to this problem ?

A: 

I've tried to reproduce the behavior you described but didn't succeed. When using the RecursiveElementNameAndTextQualifier the order of the elements doesn't seem to matter. So neither swapping int:1 and int:2, nor swapping int:3 and int:4 led to an assertion error in my tests.

I don't know which behavior you'd expect, but changing the RecursiveElementNameAndTextQualifier to a ElementNameAndTextQualifier led to assertion errors for both swapping cases.

Christoph Metzendorf