Xstream parses XML file 2

Source: Internet
Author: User

1. Create the queryorders. Java file:

/** *  */package com.saicfc.pmpf.resume.bocom.utils.resume;import java.util.List;import com.thoughtworks.xstream.annotations.XStreamAlias;import com.thoughtworks.xstream.annotations.XStreamImplicit;/** * @author lizhiyong *  */@XStreamAlias("BOCOMB2C")public class QueryOrders {        public OpRep opRep;        public OpRep getOpRep() {        return opRep;    }    public class OpRep{        public String retCode;                public String errMsg;                public OpResult opResult;                public OpResultSet opResultSet;        public String getRetCode() {            return retCode;        }        public String getErrMsg() {            return errMsg;        }                public OpResult getOpResult() {            return opResult;        }                public OpResultSet getOpResultSet() {            return opResultSet;        }            }        public class OpResult{        public String merchantID;        public String getMerchantID() {            return merchantID;        }    }        public class OpResultSet{        @XStreamImplicit(itemFieldName="opResult")        public List<OpResults> opResults;        public List<OpResults> getOpResults() {            return opResults;        }    }        public class OpResults{        public String order;                public String orderDate;                public String orderTime;                public String curType;                public String amount;                public String tranDate;                public String tranTime;                public String tranState;                public String orderState;                public String fee;                public String bankSerialNo;                public String bankBatNo;                public String cardType;                public String merchantBatNo;                public String merchantComment;                public String bankComment;        public String getOrder() {            return order;        }        public String getOrderDate() {            return orderDate;        }        public String getOrderTime() {            return orderTime;        }        public String getCurType() {            return curType;        }        public String getAmount() {            return amount;        }        public String getTranDate() {            return tranDate;        }        public String getTranTime() {            return tranTime;        }        public String getTranState() {            return tranState;        }        public String getOrderState() {            return orderState;        }        public String getFee() {            return fee;        }        public String getBankSerialNo() {            return bankSerialNo;        }        public String getBankBatNo() {            return bankBatNo;        }        public String getCardType() {            return cardType;        }        public String getMerchantBatNo() {            return merchantBatNo;        }        public String getMerchantComment() {            return merchantComment;        }        public String getBankComment() {            return bankComment;        }    }    public String signData;    public String getSignData() {        return signData;    }}

2. parse XML files:

Xstream = new xstream (New domdriver (); xstream. processannotations (queryorders. class); queryorders = (queryorders) xstream. fromxml (result); oprep = queryorders. getoprep (); string retcode = oprep. getretcode (); // return code string errmsg = oprep. geterrmsg (); // error description opresult = oprep. getopresult (); string merchantid = opresult. getmerchantid (); // merchant ID: opresultset = oprep. getopresultset (); List <opresults> List = opresultset. getopresults (); List reclist = new arraylist (); Map <string, Object> recmap = NULL; If (commonutils. isnotempty (list) {for (iterator = List. iterator (); iterator. hasnext ();) {opresults = (opresults) iterator. next (); recmap = new hashmap <string, Object> (); recmap. put ("order", opresults. getorder (); // The Order Number recmap. put ("orderdate", opresults. getorderdate (); // recmap of the order date. put ("ordertime", opresults. getordertime (); // order time recmap. put ("curtype", opresults. getcurtype (); // currency recmap. put ("amount", opresults. getamount (); // amount recmap. put ("trandate", opresults. gettrandate (); // payment date recmap. put ("trantime", opresults. gettrantime (); // payment time recmap. put ("transtate", opresults. gettranstate (); // payment transaction status recmap. put ("orderstate", opresults. getorderstate (); // recmap of the order status. put ("success", opresults. getfee (); // recmap handling fee. put ("bankserialno", opresults. getbankserialno (); // Bank serial number recmap. put ("bankbatno", opresults. getbankbatno (); // recmap of the Bank's batch number. put ("cardType", opresults. getcardtype (); // transaction card type recmap. put ("merchantbatno", opresults. getmerchantbatno (); // recmap of the merchant's batch number. put ("merchantcomment", opresults. getmerchantcomment (); // merchant remarks recmap. put ("bankcomment", opresults. getbankcomment (); // bank remarks reclist. add (recmap) ;}} string signdata = queryorders. getsigndata (); // signature data // source data to be verified string MSG = "</oprep>"; string originalstr = result. substring (result. indexof ("<oprep>"), result. indexof (MSG) + MSG. length (); Map <string, Object> map = new hashmap <string, Object> (); map. put ("retcode", retcode); map. put ("errmsg", errmsg); map. put ("merchantid", merchantid); map. put ("signdata", signdata); map. put ("originalstr", originalstr); map. put ("reclist", reclist); Return map;


Xstream parses XML file 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.