文章出處
文章列表
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; }
文章列表
全站熱搜