0

我正在尝试将两个使用 XML 单元的 xml 结构与 RecursiveElementNameAndTextQualifier 进行比较。

我的程序和 XML 如下。

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());

我总是得到错误的价值。我需要设置哪些额外的值来比较这两个 xml 结构。

4

1 回答 1

1

您的文档的问题是元素内容空白的差异,而RecursiveElementNameAndTextQualifier.

如果你添加

XMLUnit.setIgnoreWhitespace(true);

在调用similar它之前将返回true

于 2015-02-03T19:47:10.920 回答