XStream解析XMl文件

1、新建RefundResult.java文件:

/**
 * 
 */
package com.saicfc.pmpf.resume.ccb.utils;

import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;

/**
 * 解析银行返回数据
 * @author lizhiyong
 * @version $Id: QueryOrders2.java, v 0.1
		2014年7月24日 下午3:30:47 Exp $
 */
@XStreamAlias("TX")
public class RefundResult {
	@XStreamAlias("REQUEST_SN")
	public String requestSn;
	
	@XStreamAlias("CUST_ID")
	public String custId;
	
	@XStreamAlias("TX_CODE")
	public String txcode;
	
	@XStreamAlias("RETURN_CODE")
	public String returnCode;
	
	@XStreamAlias("RETURN_MSG")
	public String returnMsg;
	
	@XStreamAlias("LANGUAGE")
	public String language;
	
	@XStreamAlias("TX_INFO")
	public TxInfo2 txInfo2;
	
	public static class TxInfo2{
	    @XStreamAlias("CUR_PAGE")
	    public String curPage;
	    
	    @XStreamAlias("TPAGE")
        public String tPage;
	    
	    @XStreamImplicit(itemFieldName="LIST")
	    public List<QueryOrder> queryOrders;
	    @XStreamAlias("NOTICE")
	    public String notice;
	    
        public String getCurPage() {
            return curPage;
        }

        public String getNotice() {
            return notice;
        }

        public String gettPage() {
            return tPage;
        }

        public List<QueryOrder> getQueryOrders() {
            return queryOrders;
        }
	    
	} 

	public static class QueryOrder {
		@XStreamAlias("TRAN_DATE")
		public String tranDate;
		
		@XStreamAlias("REFUND_DATE")
		public String refundDate;
		
		@XStreamAlias("ORDER_NUMBER")
		public String orderNumber;

		@XStreamAlias("REFUND_ACCOUNT")
		public String refundAccount;
		
		@XStreamAlias("PAY_AMOUNT")
		public String payAmount;
		
		@XStreamAlias("REFUNDEMENT_AMOUNT")
		public String refundementAmount;
		
		@XStreamAlias("POS_CODE")
		public String posCode;
		
		@XStreamAlias("USERID")
		public String userId;
		
		@XStreamAlias("STATUS")
		public String status;

        public String getTranDate() {
            return tranDate;
        }

        public String getRefundDate() {
            return refundDate;
        }

        public String getOrderNumber() {
            return orderNumber;
        }

        public String getRefundAccount() {
            return refundAccount;
        }

        public String getPayAmount() {
            return payAmount;
        }

        public String getRefundementAmount() {
            return refundementAmount;
        }

        public String getPosCode() {
            return posCode;
        }

        public String getUserId() {
            return userId;
        }

        public String getStatus() {
            return status;
        }
	}

    public String getRequestSn() {
        return requestSn;
    }

    public String getCustId() {
        return custId;
    }

    public String getTxcode() {
        return txcode;
    }

    public String getReturnCode() {
        return returnCode;
    }

    public String getReturnMsg() {
        return returnMsg;
    }

    public String getLanguage() {
        return language;
    }

    public TxInfo2 getTxInfo2() {
        return txInfo2;
    }





}

2、解析XML文件:

XStream xStream = new XStream(new DomDriver());
            xStream.processAnnotations(RefundResult.class);
            RefundResult query = (RefundResult) xStream.fromXML(revResult);
            Map<String, Object> orderMap = new HashMap<String, Object>();
            orderMap.put("returnCode", query.getReturnCode());
            orderMap.put("returnMsg", query.getReturnMsg());
            //交易成功
            if ("000000".equals(orderMap.get("returnCode"))) {
                orderMap.put("requestSn", query.getRequestSn());
                orderMap.put("custId", query.getCustId());
                orderMap.put("txcode", query.getTxcode());
                orderMap.put("language", query.getLanguage());

                TxInfo2 txInfo2 = query.getTxInfo2();
                orderMap.put("curPage", txInfo2.getCurPage());
                orderMap.put("tPage", txInfo2.gettPage());

                List<QueryOrder> queryList = txInfo2.getQueryOrders();

                List queryOrderList = new ArrayList();

                Map<String, Object> queryMap = null;

                for (Iterator iterator = queryList.iterator(); iterator.hasNext();) {
                    QueryOrder queryOrder = (QueryOrder) iterator.next();
                    queryMap = new HashMap<String, Object>();
                    queryMap.put("tranDate", queryOrder.getTranDate());
                    queryMap.put("refundDate", queryOrder.getRefundDate());
                    queryMap.put("orderNumber", queryOrder.getOrderNumber());
                    queryMap.put("refundAccount", queryOrder.getRefundAccount());
                    queryMap.put("payAmount", queryOrder.getPayAmount());
                    queryMap.put("refundementAmount", queryOrder.getRefundementAmount());
                    queryMap.put("posCode", queryOrder.getPosCode());
                    queryMap.put("userId", queryOrder.getUserId());
                    queryMap.put("status", queryOrder.getStatus());

                    //把每一个订单信息都存放在queryOrderList中
                    queryOrderList.add(queryMap);
                }
                //把所有订单信息集合queryOrderList存放到orderMap中
                orderMap.put("queryOrderList", queryOrderList);
                logger.info("解析银行退款查询返回数据结束:" + orderMap);
                return orderMap;
            }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不讲理的胖子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值