Dom4j获取单节点文本值

时间:2015-09-17 15:14:23

标签: java dom4j

假设我有

<Sports>
   <Soccer>  
      <Players>  
        <Player_1> Messi Leonel </Player_1>
      </Players>  
  </Soccer>  
</Sports>  

如何使用Dom4J在一行无迭代中获取Player_1节点文本?
返回值应为:梅西莱昂内尔
感谢

1 个答案:

答案 0 :(得分:3)

得到了看起来像这样的人

File file = new File("/path/to/file.xml");
SAXReader reader = new SAXReader();
Document  document = reader.read(file);
String name = document.selectSingleNode("//Sports/Soccer/Players/Player_1").getText();