jdom xml解析

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.xml.sax.InputSource;


/**
     * 解析报文的方法
     * @param String messXmlStr 要解析的报文String
     * @author Mar
     * */
    public Map<String,String> analyzeMessXml(String messXmlStr) throws Exception{
        Map<String,String> xmlMap=new HashMap<String, String>();
        StringReader read = new StringReader(messXmlStr);
        InputSource source = new InputSource(read);//使用字符流创建新的输入源
        SAXBuilder sb = new SAXBuilder();
        Document doc =  sb.build(source);
        //Document doc = builder.build(new File("file/disk.xml"));
        Element root = doc.getRootElement();
        List<Element> eleList=root.getChildren();
        for (Element element : eleList) {
            String name=element.getName();
            if(name.equals("IF_EXIST")){
                xmlMap.put("ifExist", root.getChildText("IF_EXIST"));// 是否存在 【0 不存在 1 存在】
                if(root.getChild("QRY_ADDRESS")!=null){//[调阅]
                    xmlMap.put("url", root.getChildText("QRY_ADDRESS"));//电子保单调阅路径
                }
                if(root.getChild("LOAD_FLG")!=null){//[下载]
                    xmlMap.put("loadFlg", root.getChildText("LOAD_FLG"));//是否允许下载【 0 不允许 1 允许下载】
                }
                if(root.getChild("FLG")!=null){//[作废]
                    xmlMap.put("flg", root.getChildText("FLG"));//是否修改成功
                }
                break;
            }else if (name.equals("signature")) {// 验真接口报文
                xmlMap.put("curRevision", element.getChildText("cur_revision"));//当前验签版本
                xmlMap.put("totalRevision", element.getChildText("total_revision"));//共有版本数
                xmlMap.put("subject", element.getChildText("subject"));//签名信息【{ST=[北京], C=[CN], L=[西城区], OU=[信息技术部], O=[中华联合], CN=[XX财产保险股份有限公司]}】
                xmlMap.put("modified", element.getChildText("modified"));//签名版本的文档是否被修改,true表示被修改,false表示未被修改
                xmlMap.put("verified", element.getChildText("verified"));//签名是否有效,true表示签名有效,false表示签名无效
                break;
            }
        }
       
        return xmlMap;
    }
生如夏花之绚烂,死如秋叶之静美。
原文地址:https://www.cnblogs.com/joyblabla/p/4759899.html