Java-内联列表中具有属性的SimpleXML单深度元素

我想解析以下XML

<entry key="9" type="9">
  <value>
    <amount stake="10">50000000</amount>
    <amount stake="1">5000000</amount>
    <winner>0.0</winner>
    <description>9 Correct Numbers</description>
  </value>
</entry>

我尝试通过以下课程实现这一目标:

@Root(name="entry")
public class OddsEntryXMLObject {

    @Attribute(name="key")
    private String iKey;

    @Attribute(name="jackpot", required=false)
    private String iJackpot;

    @Attribute(name="type", required=false)
    private String iType;

    @Element(name="value")
    private OddsValueXMLObject iOddsValueXMLObject;
}

public class OddsAmountXMLObject {

    @Element(name="amount")
    private String iAmount;

    @Attribute(name="stake", required=false)
    private String iStake;
}

但是我得到以下异常:

java.lang.RuntimeException: org.simpleframework.xml.core.ValuerequiredException: Unable to satisfy @org.simpleframework.xml.Element(data=false, name=amount, required=true, type=void) on field 'iAmount' private java.lang.String OddsAmountXMLObject.iAmount for class OddsAmountXMLObject at line 1

有人知道如何解析吗?

解决方法:

提供的代码中没有OddsValueXMLObject类的声明.
假设声明是我的想法,
错误消息基本上意味着它期望在数量元素中包含一个数量元素,
像这样:

<amount>
    <amount></amount>
</amount>

当然,您拥有的XML中没有类似的东西.
您可以使用以下方法解析它:

@Root(name="entry")
public class OddsEntryXMLObject{
    @Attribute(name="key")
    private String key;

    @Attribute(name="jackpot", required=false)
    private String jackpot;

    @Attribute(name="type", required=false)
    private String type;

    @Element(name="value")
    private OddsValueXMLObject value;
}

@Root(name="value")
public class OddsValueXMLObject{
    @ElementList(inline=true)
    private java.util.List<OddsAmountXMLObject> amounts;

    @Element(name="winner", required=false)
    private String winner;

    @Element(name="description", required=false)
    private String description;
}

@Root(name="amount")
public class OddsAmountXMLObject{
    @Attribute(name="stake", required=false)
    private String stake; 

    @Text
    private String text;
}

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念