xmlnit 无法识别以下两个“相同”的 xml(除了一个已定义命名空间)文档相似:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:message xmlns:ns3="https://www.bookmarks.dev/xml/bookmarks">
<ns3:bookmarks>
<ns3:bookmark>
<ns3:name>Bookmarks and Snippets Manager</ns3:name>
<ns3:url>https://www.bookmarks.dev</ns3:url>
</ns3:bookmark>
</ns3:bookmarks>
</ns3:message>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<message>
<bookmarks>
<bookmark>
<name>Bookmarks and Snippets Manager</name>
<url>https://www.bookmarks.dev</url>
</bookmark>
</bookmarks>
</message>
比较两者的失败单元测试:
@Test
void givenSameMessageOneWithoutNamespace_shouldBeSimilar() {
ClassLoader classLoader = getClass().getClassLoader();
final var withNamespaceInput =
Input.from(
new File(classLoader.getResource("with-namespace.xml").getFile()));
final var noNamespaceInput =
Input.from(
new File(
classLoader
.getResource("no-namespace.xml")
.getFile()));
final Diff documentDiff =
DiffBuilder.compare(withNamespaceInput)
.withTest(noNamespaceInput)
.checkForSimilar()
.build();
assertThat(documentDiff.hasDifferences()).isFalse();
}
差异体现在Expected namespace uri 'null' but was 'https://www.bookmarks.dev/xml/bookmarks' - comparing <message...> at /message[1] to <ns3:message...> at /message[1] (DIFFERENT)
...
任何想法如何配置比较器以忽略第二个文档中缺少的前缀?