Java比较Xml文件
添加依赖
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>x.y.z</version>
</dependency>
代码
Source control = Input.fromFile("test-data/good.xml").build();
Source test = Input.fromByteArray(createTestDocument()).build();
DifferenceEngine diff = new DOMDifferenceEngine();
diff.addDifferenceListener(new ComparisonListener() {
public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) {
Assert.fail("found a difference: " + comparison);
}
});
diff.compare(control, test);
更多功能文档地址
https://github.com/xmlunit/xmlunit
Loading...