public static void main(String arge[]) {
long lasting = System.currentTimeMillis();
try {
File f = new File("E://Java Object//xml-sax-dom//DOM-xml-SAX//db-config.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read(f);
Element root = doc.getRootElement();
Element foo;
for (Iterator i = root.elementIterator("driver"); i.hasNext();) {
foo = (Element) i.next();
System.out.println("数据库类型:" + foo.elementText("db-type"));
System.out.println("驱动程序:" + foo.elementText("driver-class"));
System.out.println("连接字符串:" + foo.elementText("connectString"));
System.out.println("主机名称:" + foo.elementText("server-name"));
System.out.println("端口:" + foo.elementText("port"));
System.out.println("数据库名称:" + foo.elementText("db-name"));
System.out.println("用户名:" + foo.elementText("user"));
System.out.println("密码:" + foo.elementText("pwd"));
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("运行时间:" + (System.currentTimeMillis() - lasting) + " 毫秒");
}
最简单的一个XML解析-dom4j
最新推荐文章于 2025-08-12 20:39:53 发布