`

dom4j 解析xml字符串

    博客分类:
  • xml
 
阅读更多

 

/**

*path xml字符串

*ndename 节点名称

*/

public static Node analytic(String path, String nodeName) {
  Document doc = null;
  try {
   doc = DocumentHelper.parseText(path);
  } catch (DocumentException e) {   
   e.printStackTrace();
  }
  XPath xpathSelector = DocumentHelper.createXPath(nodeName);
  Node node = xpathSelector.selectSingleNode(doc);
  return node;
 }

 

(2)--------------

        Document  doc = DocumentHelper.parseText(sbuf); // 将字符串转为XML
        Element rootElt = doc.getRootElement(); // 获取根节点
        notice.setVersion(rootElt.elementText("Version"));

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics