Stringxxml="<listhospital>"+ "<count>153</count>"+ "<hospital>"+ "<id>12</id>"+ "<name>北京大学第一医院</name>"+ "</hospital>"+ "<hospital>"+ "<id>13</id>"+ "<name>北京大学第一医院</name>"+ "</hospital>"+ "</listhospital>"; XStreamxstream=newXStream(newDomDriver());//注意:不是newXstream();否则报错: xstream.processAnnotations(Result.class); Resultperson=(Result)xstream.fromXML(xxml); System.out.println(person.toString());
注解
@XStreamAlias("listhospital") publicclassResult{ @XStreamAlias("count") privateintcount; @XStreamImplicit(itemFieldName="hospital") privateList<Hospital>listHospital; 简略getset }
publicclassHospital{ @XStreamAlias("id") privateintid; @XStreamAlias("name") privateStringname; 简略getset