欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

dom4j解释XML 博客分类: Java xmldom4j 

程序员文章站 2024-02-21 15:59:58
...
public static RegistrationOTPResponse parserRegXML(String result) {
		
		RegistrationOTPResponse response = new RegistrationOTPResponse();
		String resultCode = null;
		String key = null;
		
		if(result == null){
			response = null;
		}else{
			
			try {
				//可传入path或者Reader类型
				Document doc = new SAXReader().read(new StringReader(result));
				
				Element resultRoot = doc.getRootElement();
				Element regKeyRoot = doc.getRootElement();
				//获取大标题
				Element resultElement = resultRoot.element("result");
				//大标题下的小标题
				resultCode = resultElement.elementText("resultCode");
				
				if(resultCode.equals("0")){
					//获取大标题
					Element regKeyElement = regKeyRoot.element("regKey");
					//大标题下的小标题
					key = regKeyElement.elementText("key");
					response.setRegKey(key);
				}
				
				response.setResultcode(resultCode);
				
				
				doc.clearContent();
			} catch (DocumentException e) {
				// TODO Auto-generated catch block
				logger.debug("parserXML error..." + e.getMessage());
			}
			
		}
		

		return response;
	}

 

 参考:

http://www.cnblogs.com/shitianzeng/articles/2518323.html

相关标签: xml dom4j