• 解析xml,判断是否含有某字符串


    public class MCommonUtil {
        static boolean result = false;
        /**
         * 获取xml结果
         * @param protocolXML-xml字符串
         * @param findtxt-要查询的字符串
         * @return
         */
        public static boolean parse(String protocolXML,String findtxt){
            boolean results = false;
            try{
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();   
                Document doc = builder.parse(new InputSource(new StringReader(protocolXML)));
                Element root = doc.getDocumentElement();   
                NodeList nodes = root.getChildNodes();   
                results = foreach(nodes,findtxt);
                result = false;
            }catch(Exception e){
                e.printStackTrace();
            }
            return results;
        }
        /**
         * 递归处理遍历xml
         * @param nodelist
         * @param findtxt
         * @return
         */
        public static boolean foreach(NodeList nodelist,String findtxt){
            if(nodelist!=null){
                for(int i=0;i<nodelist.getLength();i++){
                    Node node = nodelist.item(i);
                    if(node.getFirstChild()!=null){   
                        if(findtxt.equals(node.getFirstChild().getNodeValue())){
                            result = true;
                            break;
                        }
                    }
                    if(result == false){                    
                        foreach(node.getChildNodes(),findtxt);
                    }
                }
            }
            return result;
        }
    }
  • 相关阅读:
    串 --- 匹配
    串 --- 匹配
    计算几何 --- 哈希优化
    哈希 --- 线性探测法
    拓扑排序 --- 反向建图
    swift学习
    CocoaPods安装教程 pod setup很慢解决方案
    Adobe Fireworks CS6 Mac破解版
    iStat for mac
    mac环境下清理系统垃圾clearMyMac 3.9 破解版
  • 原文地址:https://www.cnblogs.com/jassy/p/8148902.html
Copyright © 2020-2023  润新知