【问题标题】:Deserializing XML @Element and @ElementList with same name from different XML datasets反序列化来自不同 XML 数据集的具有相同名称的 XML @Element 和 @ElementList
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-14
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      • 1970-01-01
      • 2017-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多