1、bean to xml:
public static void main(String[] args) {
List<JydInfo> list = new ArrayList<JydInfo>();String auth_code = "hunan_auth_code";
JydInfo clws1 = new JydInfo("100101","黑猪","100","2000","12.5","11111111111111111111,222222222222,33333333333333",
"20140811434240101011","2014-04-13","2014-08-11","散户","1舍","潘文",
"2014年3月29号出生;4月23号打猪瘟疫苗;4月29号断奶,打蓝耳,伪狂犬,口蹄疫疫苗;使用尿素作牛羊饲料的添加剂,取得良好效果;",
"434240101","红星养殖场","034022031","胡泽","湘A88356");
JydInfo clws2 = new JydInfo("100102","白猪","1000","20000","13.5","33333333333,111111111111","2014-05-13","2014-08-21","2舍",
"2014年4月29号出生;5月23号打猪瘟疫苗;5月29号断奶,打蓝耳,伪狂犬,口蹄疫疫苗;使用尿素作牛羊饲料的添加剂,取得良好效果;","章泽","湘A11111");
list.add(clws1);
list.add(clws2);
JydInfos jydinfos = new JydInfos(list);
Req req = new Req(auth_code,jydinfos);//这个类包含两个成员变量:list类型和一个String类型
try {
JAXBContext context = JAXBContext.newInstance(Req.class);
Marshaller marshaller = context.createMarshaller();
StringWriter sw = new StringWriter();
marshaller.marshal(req,sw);
//转换后的xml
System.out.println(sw.toString());
} catch (JAXBException e) {
e.printStackTrace();
}
}