Jav解析soap的xml

阅读更多

解析xml

import org.dom4j.Document;

import org.dom4j.DocumentHelper;

import org.dom4j.Element;

import org.dom4j.io.SAXReader;

import org.dom4j.xpath.DefaultXPath;


	
		
			
				
					11
					
						0
					
				
			
		
	

 

 

解析代码;

 

 /**
     * 解析 返回的消息体   //后面修改为通用方法 
     * 
     * parseSoapXml:(这里用一句话描述这个方法的作用). 
* * @author * @param xmlStr * @return * @throws Exception * @since JDK 1.6 * @Date:2015-4-8下午8:05:31 */ private boolean parseSoapXml(String xmlStr) throws Exception { Map map = new HashMap(); SAXReader saxReader = new SAXReader(); Document document = DocumentHelper.parseText(xmlStr); DefaultXPath xpath = new DefaultXPath("//n:return"); xpath.setNamespaceURIs(Collections.singletonMap("n", "http://vp.xx.com")); List list = xpath.selectNodes(document); Iterator iterator = list.iterator(); if (iterator.hasNext()) { Element node = (Element) iterator.next(); List l = node.elements(); Element flagNode = node.element("vPX1Result").element("vPXResult").element("flag"); if (StringUtils.equals("0", flagNode.getText())) { map.put("flag", flagNode.getText()); return true; } else { return false; } // Element portNode = node.element("port"); //map.put("port", portNode.getText()); } return false; }

 

你可能感兴趣的:(Jav解析soap的xml)