java SAXReader解析xml配置文件

  

 

在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

你可能感兴趣的:(reader)