public static String getConnString(String dbAttribute)
{
String result = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
try {
 DocumentBuilder builder = factory.newDocumentBuilder();
 
 Document doc = builder.parse("connstring.xml");
 doc.normalize();
 Element elm = doc.getDocumentElement();
 NodeList nodes = elm.getElementsByTagName(dbAttribute);
 //
 for(int i=0;i<nodes.getLength();i++)
 {
 Element node = (Element)nodes.item(i);
 result = node.getElementsByTagName("connstring").item(0).getFirstChild().getNodeValue().toString();
 }
 nodes=null;
 elm=null;
 doc=null;
 builder=null;
}
catch (Exception e){
}
finally{
factory=null;
}
return result;
}
//执行这个函数,大概需要2秒的时间
//我一直注释到Document doc = builder.parse("connstring.xml")这行代码,执行速度才比较快一些
//Java读取xml没这么慢吧?或者我用的这种方法速度比较慢?