【发布时间】:2019-12-08 19:38:16
【问题描述】:
我希望比较两个 XML 文件并确定它们是否具有相同的结构,即相同类型和数量的标签,最好具有相同的属性。标签和属性的值可能不同。
此代码检测所有差异。即使结构相同但值不同。我想改进它以仅检测结构差异。
public static List compareXML(Reader source, Reader target) throws
SAXException, IOException{
//creating Diff instance to compare two XML files
Diff xmlDiff = new Diff(source, target);
//for getting detailed differences between two xml files
DetailedDiff detailXmlDiff = new DetailedDiff(xmlDiff);
return detailXmlDiff.getAllDifferences();
}
【问题讨论】:
标签: java xml dom xml-parsing xmlunit