srinannapa
srinannapa

Reputation: 3207

Comparing XML with XML unit using RecursiveElementNameAndTextQualifier

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.

Upvotes: 0

Views: 97

Answers (1)

user4524982
user4524982

Reputation:

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.

Upvotes: 1

Related Questions