simplexml 重复元素
我有一个如下所示的 xml:
<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 行声明了两次
我该如何摆脱这个问题?任何人的解决方案都受到高度赞赏。
提前致谢。
i have an xml which looks like this:
<A>
<C/>
<B/>
<B/>
</A>
in the xml mapping java code i have something like this:
public class A {
@Element(required=false)
private int B;
@Element(required=false)
private int C;
//getters and setters...
}
but i am getting an error like this:
org.simpleframework.xml.core.PersistenceException: Element 'B' declared twice at line 1
how do i get rid of this problem? solution from anyone is highly appreciated.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的 Xml 中,您有 2 个 B 元素,因此在您的 POJO 中,您需要为 B 提供某种类型的集合(即列表),因为它可以在 XML 中出现 0 次或多次。
In your Xml you have 2 B elements so in your POJO you need to have a collection of some sort (i.e. a List) for B since it can appear in the XML 0 or more times.