XStreamは簡単なXMLファイル2を生成する

4528 ワード

1、新しいRequestInfo.JAvaファイル:
package com.saicfc.pmpf.resume.ccb.utils;


/**
 *  
 * @author lizhiyong
 * @version $Id: RequestInfo.java, v 0.1
		2014 7 24   2:43:39 Exp $
 */
public class RequestInfo {
    
    public String REQUEST_SN;
    public String CUST_ID;
    public String USER_ID;
    public String PASSWORD;
    public String TX_CODE;
    public String LANGUAGE;
    public TxInfo TX_INFO;
    
    public RequestInfo(String rEQUEST_SN, String cUST_ID, String uSER_ID, String pASSWORD,
                       String tX_CODE, String lANGUAGE) {
        REQUEST_SN = rEQUEST_SN;
        CUST_ID = cUST_ID;
        USER_ID = uSER_ID;
        PASSWORD = pASSWORD;
        TX_CODE = tX_CODE;
        LANGUAGE = lANGUAGE;
    }

    public void setREQUEST_SN(String rEQUEST_SN) {
        REQUEST_SN = rEQUEST_SN;
    }

    public void setCUST_ID(String cUST_ID) {
        CUST_ID = cUST_ID;
    }

    public void setUSER_ID(String uSER_ID) {
        USER_ID = uSER_ID;
    }

    public void setPASSWORD(String pASSWORD) {
        PASSWORD = pASSWORD;
    }

    public void setTX_CODE(String tX_CODE) {
        TX_CODE = tX_CODE;
    }

    public void setLANGUAGE(String lANGUAGE) {
        LANGUAGE = lANGUAGE;
    }

    public void setTX_INFO(TxInfo tX_INFO) {
        TX_INFO = tX_INFO;
    }
    
  
    
    
}
、新規TxInfo.JAvaファイル:
package com.saicfc.pmpf.resume.ccb.utils;

public class TxInfo {
    public String START;
    public String STARTHOUR;
    public String STARTMIN;
    public String END;
    public String ENDHOUR;
    public String ENDMIN;
    public String KIND;
    public String ORDER;
    public String ACCOUNT;
    public String DEXCEL;
    public String MONEY;
    public String NORDERBY;
    public String PAGE;
    public String POS_CODE;
    public String STATUS;
    
    
    public TxInfo(String sTART, String sTARTHOUR, String sTARTMIN, String eND, String eNDHOUR,
                  String eNDMIN, String kIND, String oRDER, String aCCOUNT, String dEXCEL,
                  String mONEY, String nORDERBY, String pAGE, String pOS_CODE, String sTATUS) {
        START = sTART;
        STARTHOUR = sTARTHOUR;
        STARTMIN = sTARTMIN;
        END = eND;
        ENDHOUR = eNDHOUR;
        ENDMIN = eNDMIN;
        KIND = kIND;
        ORDER = oRDER;
        ACCOUNT = aCCOUNT;
        DEXCEL = dEXCEL;
        MONEY = mONEY;
        this.NORDERBY = nORDERBY;
        PAGE = pAGE;
        POS_CODE = pOS_CODE;
        STATUS = sTATUS;
    }
    
    
    public void setSTART(String sTART) {
        START = sTART;
    }
    public void setSTARTHOUR(String sTARTHOUR) {
        STARTHOUR = sTARTHOUR;
    }
    public void setSTARTMIN(String sTARTMIN) {
        STARTMIN = sTARTMIN;
    }
    public void setEND(String eND) {
        END = eND;
    }
    public void setENDHOUR(String eNDHOUR) {
        ENDHOUR = eNDHOUR;
    }
    public void setENDMIN(String eNDMIN) {
        ENDMIN = eNDMIN;
    }
    public void setKIND(String kIND) {
        KIND = kIND;
    }
    public void setORDER(String oRDER) {
        ORDER = oRDER;
    }
    public void setACCOUNT(String aCCOUNT) {
        ACCOUNT = aCCOUNT;
    }
    public void setDEXCEL(String dEXCEL) {
        DEXCEL = dEXCEL;
    }
    public void setMONEY(String mONEY) {
        MONEY = mONEY;
    }
    public void setNORDERBY(String nORDERBY) {
        NORDERBY = nORDERBY;
    }
    public void setPAGE(String pAGE) {
        PAGE = pAGE;
    }
    public void setPOS_CODE(String pOS_CODE) {
        POS_CODE = pOS_CODE;
    }
    public void setSTATUS(String sTATUS) {
        STATUS = sTATUS;
    }
    
    
}

3、XMLファイルを生成する:
 XStream xStream = new XStream(new DomDriver("GB2312", new XmlFriendlyNameCoder("-_", "_")));
この行は変換下線です
 XStream xStream = new XStream(new DomDriver("GB2312", new XmlFriendlyNameCoder("-_", "_")));
 xStream.alias("TX", RequestInfo.class);
 RequestInfo requestInfo = new RequestInfo(requestSn, custId, userId, password, txcode,
            language);
 requestInfo.setTX_INFO(new TxInfo(start, startHour, startMin, end, endHour, endMin, kind,
            order, account, dexcel, money, norderby, page, pos_code, status));
 String top = "<?xml version=\"1.0\" encoding=\"GB2312\" standalone=\"yes\" ?> 
"; String xml = top + xStream.toXML(requestInfo);