dom4j解释XML

阅读更多
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)