2014-10-05 62 views
0

我想使用SimpleXML将不同组的XML序列化数据反序列化为一个类(不是同一时间)。从不同的XML数据集中反序列化具有相同名称的XML @Element和@ElementList

所有的数据集都有一个根类<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; 
} 

回答

1

解决此问题的最简单方法是始终使用多个元素。只需删除与单个元素相关的代码。

相关问题