论坛首页 Java企业应用论坛

java SAXReader解析xml配置文件

浏览 3073 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-10-28  

  

 

在main方法里,简单的测试一下

 

   public static void main(String[] args) throws DocumentException, IOException {
  
   SAXReader reader=new SAXReader();
   Document doc=null;
   doc= reader.read("src/hibernate.cfg.xml");
   List<Node>  node1=doc.selectNodes("//hibernate-configuration/session-factory/property/@name");
   for (Node node:node1) {
   System.out.println(node.getText().trim()+":"+node.getParent().getText().trim());
   }
  
 }

 

结果:

connection.username:liss3
connection.url:jdbc:oracle:thin:@192.168.12.11:1521:liss3
dialect:org.hibernate.dialect.Oracle9Dialect
show_sql:true
myeclipse.connection.profile:oracle.jdbc.driver.OracleDriver
connection.password:liss
connection.driver_class:oracle.jdbc.driver.OracleDriver
hibernate.connection.release_mode:auto
hibernate.connection.provider_class:org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.min_size:1
hibernate.c3p0.max_size:30
hibernate.c3p0.timeout:60
hibernate.c3p0.max_statements:0
hibernate.c3p0.idle_test_period:60
hibernate.c3p0.acquire_increment:1

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics