XStream生成简单的XMl文件

前端之家收集整理的这篇文章主要介绍了XStream生成简单的XMl文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、生成简单的XML文件

1、新建ResumeToXml.java文件

package com.saicfc.pmpf.resume.bocom.utils.resume;


/**
 * 把Java对象转化成xml
 * @author lizhiyong 
 * @version $Id: RefundToXml.java,v 0.1
		2014年6月5日 下午3:44:54 Exp $
 */
@SuppressWarnings("unused")
public class ResumeToXml {
    private String opName;
    private ReqParam  reqParam;
    
    
    public ResumeToXml(String opName) {
        super();
        this.opName = opName;
    }


    public void setOpName(String opName) {
        this.opName = opName;
    }


    public void setReqParam(ReqParam reqParam) {
        this.reqParam = reqParam;
    }

}

2、新建ReqParam.java文件


package com.saicfc.pmpf.resume.bocom.utils.resume;

@SuppressWarnings("unused")
public class ReqParam{
    private String merchantID;
    
    private int number;
    
    private int detail;
    
    private String orders;

    public ReqParam(String merchantID,int number,int detail,String orders) {
        this.merchantID = merchantID;
        this.number = number;
        this.detail = detail;
        this.orders = orders;
    }

    public void setMerchantID(String merchantID) {
        this.merchantID = merchantID;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public void setDetail(int detail) {
        this.detail = detail;
    }

    public void setOrders(String orders) {
        this.orders = orders;
    }
    
    
}

3、生成XML文件

XStream xStream = new XStream(new DomDriver());
xStream.alias("BOCOMB2C",ResumeToXml.class);
ResumeToXml resumeToXml = new ResumeToXml("cb2202_queryOrderOp");
resumeToXml.setReqParam(new ReqParam(merchantID,number,detail,orderNos));
String top = "<?xml version=\"1.0\" encoding=\"gb2312\"?> \n";
String xml = top + xStream.toXML(resumeToXml);
原文链接:https://www.f2er.com/xml/298017.html

猜你在找的XML相关文章