0

I'm trying to compare two xml structure's using XML Unit with RecursiveElementNameAndTextQualifier.

My Program and XML's are below.

String control = "<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>";

String test = "<root> "+ 
      "<ent> "+ 
           "<value> "+ 
            " <int>3</int>  "+ 
           "</value> "+ 
           "<value> "+ 
           " <int>4</int>"+   
           "</value> "+ 
      "</ent>  "+ 
     " <ent> "+ 
           "<value> "+ 
           "  <int>1</int>"+   
          " </value> "+ 
          " <value> "+ 
          "   <int>2</int>  "+ 
          " </value> "+ 
     " </ent> "+ 
    "</root>";

        Diff d = new Diff(control,test);
            d.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
System.out.println(d.similar());

I'm always getting false as value. What are the extra values I need to set to compare those two xml structures.

yankee
  • 38,872
  • 15
  • 103
  • 162
srinannapa
  • 3,085
  • 8
  • 49
  • 66

1 Answers1

1

The problem with your documents is a difference in element content whitespace which is not ignored by RecursiveElementNameAndTextQualifier.

If you add

XMLUnit.setIgnoreWhitespace(true);

before invoking similar it is going to return true.

Stefan Bodewig
  • 3,260
  • 15
  • 22