2011-11-25 132 views
1

我有一个XML,看起来像这样:SimpleXML的重复元素

<A> 
    <C/> 
    <B/> 
    <B/> 
</A> 

在XML映射Java代码中,我有这样的事情:

public class A { 
    @Element(required=false) 
    private int B; 

    @Element(required=false) 
    private int C; 
    //getters and setters... 
} 

但我得到这样的错误: org.simpleframework.xml.core.PersistenceException:元素'B'在第1行声明了两次

我该如何摆脱此问题?任何人的解决方案都是非常感谢

在此先感谢。

+0

你在使用什么潜在的编组器?从“@Element”注释不立即显而易见... – pap

回答

2

在你的Xml中,你有2个B元素,所以在你的POJO中,你需要有一个B的集合(即List),因为它可以出现在XML 0或更多次。

1
public class A { 
    @ElementList(inline=true,required=false, entry="B") 
    private List<Integer> B; 

    @ElementList(inline=true,required=false, entry="C") 
    private List<Integer> C; 
    //getters and setters... 
} 
+0

我认为只有'B'是一个列表。 –