2008-01-21

dom4j操作xml

关键字: dom4j xml
<Elements   xmlns="http://www.163.com"   xmlns:dc="http://www.163.com"> 
       <test>
          <title> 标题 </title>    
       </test> 
</Elements>
SAXReader saxReader = new SAXReader();     
Document document = saxReader.read(new File(filename));    

HashMap xmlMap = new HashMap();   
xmlMap.put("plugins","http://www.163.com");   //假设的命名空间
XPath x = document.createXPath("//plugins:test/plugins:title");   //读取二级节点,研究了半天
x.setNamespaceURIs(xmlMap);            
Element valueElement = (Element)x.selectSingleNode(document);   
System.out.println(valueElement.getText());   //输出该节点内容
评论
发表评论

您还没有登录,请登录后发表评论