使用SimpleXML / Simple框架混合值和元素

时间:2013-08-06 20:05:29

标签: android xml simple-framework

我要解析以下XML(这只是国家数字预测数据库的一部分):

<production-center>
    Meteorological Development Laboratory
    <sub-center>Product Generation Branch</sub-center>
</production-center>

我创建了以下类来使用它:

@Element
public class ProductionCenter {
    @Element(name = "sub-center")
    public String subCenter;

    @Text(required = false)
    public String value;
}

然而,这不起作用,因为它只期望Text作为值,并且还有一个额外的元素。

如何让Simple Framework对这个XML结构感到满意?我无法更改XML,因此不能选择它。

- 我也尝试了以下内容 -

@Element
public class ProductionCenter {
    @Text
    @ElementListUnion({
        @ElementList(entry="sub-center", type=String.class, inline=true),
    })
    public List<Object> values;
}

1 个答案:

答案 0 :(得分:1)

您不能同时使用String.class类型的@Text和@ElementListUnion。一旦我尝试没有@Text Simple Framework就更快乐了。

相关问题