dom4j怎么获得指定名称的节点信息

例如: XML信息如下

xml  version = "1.0"  encoding = "utf-8"  ?> 
  < MgUtil >
     < db_config >
         < db_driver >oracle.jdbc.driver.OracleDriver db_driver >
         < db_url >dbc:oracle:thin:@172.16.1.101:1521:orcl db_url >
         < db_user >zdyn db_user >
         < db_password >zdyn db_password >
     db_config >
     < relationFactory >
         < classInfo > classInfo >
     relationFactory >
  MgUtil >

比如想要获得叫db_driver的节点里面的信息

获取的代码如下:

String xml ="...";
Document doc = DocumentHelper.parseText(xml);
Element root = doc.getRootElement();
Element db_config = root.element("db_config");
Element db_driver = db_config.element("db_driver");
String val_db_driver= db_driver.getTextTrim();


你可能感兴趣的:(JavaSE)