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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.