首页 > 其他 > 详细

DocumentBuilder 解析出指定节点XMLString数据

时间:2014-02-27 01:36:33      阅读:495      评论:0      收藏:0      [点我收藏+]
/**
     * 获取指定的节点key
     * @param xmlString
     * @param elementKey
     * @return
     */
    public static String parseXMLStringTOGetElement(String xmlString,String elementKey){
        DocumentBuilder builder = XMLHelper.getDocumentBuilder();
        try {
            Document document = builder.parse(new InputSource(new StringReader(xmlString)));
            NodeList nodeList = document.getElementsByTagName(elementKey);
            if(nodeList!=null && nodeList.getLength()>0){
                return nodeList.item(0).getFirstChild().getNodeValue();
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
    
    /**
     * 获取DocumentBuilder对象
     * @return
     */
    public static DocumentBuilder getDocumentBuilder(){
        try {
            return DocumentBuilderFactory.newInstance().newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
            return null;
        }
    }

DocumentBuilder 解析出指定节点XMLString数据,布布扣,bubuko.com

DocumentBuilder 解析出指定节点XMLString数据

原文:http://blog.csdn.net/l1028386804/article/details/19941049

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!