File file = new File("D:\\98103271NEW.XML");
Document doc = null;
if (file.exists()) {
SAXReader builder = new SAXReader();
try {
builder.setValidation(false);
builder.setEntityResolver(new Trs2SolrData_ModelData());
doc = builder.read(file);
// System.out.println(doc);
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("can not find xml file:"
+ file.getAbsolutePath());
}
Document doc = null;
if (file.exists()) {
SAXReader builder = new SAXReader();
try {
builder.setValidation(false);
builder.setEntityResolver(new Trs2SolrData_ModelData());
doc = builder.read(file);
// System.out.println(doc);
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("can not find xml file:"
+ file.getAbsolutePath());
}
return doc;
重点是如下两句:
builder.setValidation(false);
builder.setEntityResolver(new Trs2SolrData_ModelData());
但,我觉得用这些工具都不如用java的String来解析比较实际,并快速