读书人

java写的一个对像xml序列弥合析的demo

发布时间: 2012-10-07 17:28:51 作者: rapoo

java写的一个对像xml序列化解析的demo
1.下载附件中的xstream-1.1.3.jar包
2.建立一个文件Integral.java代码如下:
public class Integral {
private int caseId;
private Date surveyCompleteTime;

public int getCaseId() {
return caseId;
}

public void setCaseId(int caseId) {
this.caseId = caseId;
}

public Date getSurveyCompleteTime() {
return surveyCompleteTime;
}

public void setSurveyCompleteTime(Date surveyCompleteTime) {
this.surveyCompleteTime = surveyCompleteTime;
}

public static void main(String[] args) {
XStream xstream = new XStream(new DomDriver());
xstream.alias("Integral", Integral.class);
Integral i = new Integral();
i.setSurveyCompleteTime(Calendar.getInstance().getTime());
i.setCaseId(120);
String xml = xstream.toXML(i);
System.out.println(xml);
Integral i2 = (Integral) xstream.fromXML(xml);
System.out.println(i2.getCaseId() + "|" + i2.getSurveyCompleteTime());
}
}

读书人网 >XML SOAP

热点推荐