我有一个使用 XmlUnit 从两个 XML 文件中获取差异的应用程序。但问题是 XmlUnit 使用 JDOM。我的 xml 文件大约 1GB 大!
将这些 xml 存储在 JDOM 文档中需要太多 RAM。
我曾尝试使用 SlimJDOMFactory 但仍然使用太多 RAM!
实际上我需要在 XML 文件中向前和向后导航。如果没有 JDOM,我没有找到简单的方法。
任何人都可以帮忙吗?
这是关于我如何构建 JDOM 文档的代码示例:
private org.jdom2.Document refDocJdom2;
private org.jdom2.Document resDocJdom2;
SAXBuilder sxb = new SAXBuilder();
sxb.setJDOMFactory(new SlimJDOMFactory());
popmsg("Validating reference file...");
try {
refDocJdom2 = sxb.build(referenceXML_Path);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error while parsing Reference : "+referenceXML_Path+" file.\nCheck XML file validity.");
return;
}
popmsg("Reference file validated");
popmsg("Validating result file....");
try {
resDocJdom2 = sxb.build(resultXML_Path);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error while parsing result "+resultXML_Path+" file.\nCheck XML file validity.");
return;
}
popmsg("Result file validated");
popmsg("Validation Done.");
getDifferencies(referenceXML_Path, resultXML_Path);
d2 = new Date();
}
public void getDifferencies(String fileRef, String fileRes) throws SAXException, IOException {
popmsg("Documents : VALID XML format");
popmsg("Shearching for differencies....");
Reader refReader;
refReader = new FileReader(fileRef);
Reader resReader = new FileReader(fileRes);
Diff aDifference = new Diff(refReader, resReader);
if(refReader != null){
refReader.close();
}
refReader = null;
if(resReader != null){
resReader.close();
}
resReader = null;
//TODO
// XMLUnit.setIgnoreWhitespace(true);
myDetailledDiff = new DetailedDiff(aDifference);
myDetailledDiff.overrideDifferenceListener(new IgnoreNamedElementsDifferenceListener());
myDetailledDiff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
allDiffs = myDetailledDiff.getAllDifferences();
myDetailledDiff = null;
popmsg("Got all differencies...\nGoing to Sort them now...");
popmsg("Diff SIZE : "+allDiffs.size());
myDiffsList = new ArrayList<MyDifference>(allDiffs.size());
if(allDiffs.size() > 0){
Difference aDiff;
for (int i = 0; i < allDiffs.size(); i++){
aDiff = (Difference) allDiffs.get(i);
myDiffsList.add(new MyDifference(aDiff, refDocJdom2, resDocJdom2));
if(myDiffsList.size() == LIMIT)
return ;
if (i%25 == 0 && i!= 0){
popmsg("**************************************************\t"+i+"\n");
}
}
allDiffs.clear();
allDiffs = null;
}else{
popmsg("NO DIFERENCIES");
}
}