用dom4j 解析 普通的XML速度倒是挺快的。。
但是解析hbm.xml的时候 时间就会很慢。。
我只是取其中的id的部分节点值 肿么可以更高效的读取呢??
现在读取的话 大概4个HBM.XML 需要2分多钟才能出来。。
而且2个HBM都不超过10个字段 没有set。
2个方法:
[code="java"]
//读取XML文件返回doc实体
public Document getDocumentByPath(String path){
SAXReader saxReader = new SAXReader();
Document document;
String end="";
try {
document = saxReader.read(path);
return document;
} catch (DocumentException e) {
e.printStackTrace();
return null;
}
}
//读取需要的节点值 并返回
public String getXmlValue(Document doc,String rootName){
SAXReader saxReader = new SAXReader();
Document document=doc;
String end="";
try {
//获取并返回所有对应节点的属性值
List list = document.selectNodes(rootName);
Iterator iter = list.iterator();
while (iter.hasNext()) {
Attribute attribute = (Attribute) iter.next();
end=attribute.getValue();
break;
}
return end;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
[/code]
求指点。。