2011-11-25 77 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'是一個列表。 –