【发布时间】:2014-10-06 05:55:03
【问题描述】:
我想使用 SimpleXML 将不同的 XML 序列化数据集反序列化为一个类(不是同时)。
所有数据集都有一个根类<body/>,但有不同的子类。有些有<prediction> 的一个元素,其他<prediction> 的多个元素。 <route> 也一样。这是我目前使用的代码,但它给了我一个PersistenceException 类型的错误(“重复注释”)。
解决这个问题的最简单方法是什么?任何帮助,将不胜感激。
@Root(name = "body", strict = false)
class NextBusAPIResult {
@Attribute(name = "copyright")
public String Copyright;
@Element(name = "predictions", required = false, type = Predictions.class)
public Predictions Predictions;
@ElementList(name = "predictions", required = false, inline = true)
public List<Predictions> PredictionsForMultiStops;
@Element(name = "route", required = false, type = RouteInfo.class)
public RouteInfo RouteInfo;
@ElementList(name = "route", required = false, inline = true)
public List<RouteSchedule> RouteSchedules;
}
【问题讨论】:
标签: java android xml xml-parsing deserialization