如何在使用XMLUnit的DetailedDiff函数时仅检查特定节点而不是所有节点的差异
这是我的代码:
public static void main(String[] args)
{
//URL url1 = xmlunittest.class.getResource("MSHIS1.xml");
// URL url2 = xmlunittest.class.getResource("MSHIS.xml");
Logger L = new Logger();
FileReader fr1 = null;
int countofdifferences = 0;
FileReader fr2 = null;
try {
fr1 = new FileReader("MSHIS.xml");
fr2 = new FileReader("MSHIS1.xml");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
Diff diff = new Diff(fr1, fr2);
L.writeToBVTLOG("Similar? " + diff.similar());
L.writeToBVTLOG("Identical? " + diff.identical());
DetailedDiff detDiff = new DetailedDiff(diff);
List differences = detDiff.getAllDifferences();
for (Object object : differences) {
Difference difference = (Difference)object;
L.writeToBVTLOG("------------------------");
L.writeToBVTLOG(difference.toString());
L.writeToBVTLOG("------------------------");
countofdifferences++;
}
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
L.writeToBVTLOG(countofdifferences);
}但问题是,我只想让程序告诉我4个特定节点是否发生了任何更改。那么如何通过列出所有差异来实现这一点呢?
发布于 2012-06-13 09:41:11
您可以先用javax.xml.transform.TransformerFactory转换这两个文档,这样它就只包含您感兴趣的节点。或者,您可以对差异使用getControlNodeDetail()和getTestNodeDetail()来查看差异是否适用于您想要的节点。
https://stackoverflow.com/questions/10998229
复制相似问题