`
zyz611
  • 浏览: 97073 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

xpath dom 解析

    博客分类:
  • java
 
阅读更多
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         DocumentBuilder builder = factory.newDocumentBuilder();
         FileInputStream file = new FileInputStream(legoInstalledFile);
         Document doc = builder.parse(file);
        
        
         XPathFactory xPathFactory = XPathFactory.newInstance();
         XPath xpath = xPathFactory.newXPath();
         XPathExpression expr = xpath.compile("//install/installpath");
         Object result = expr.evaluate(doc, XPathConstants.NODESET);
        
         NodeList nodes = (NodeList) result;
       NamedNodeMap attributes = nodes.item(0).getAttributes();
       return attributes.item(0).getTextContent();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics