首页 > 代码库 > 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);
XStream生成简单的XMl文件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。