问题描述
s在开始一个项目之前,我想在这里做一个简短的提醒.
sBefore starting a project I wanted to get a short heads up here.
如果我有这样的结构:
<root> <a> <a> <a> <a> <a/> </a> </a> </a> <a> </a> </a>
a 元素可以容纳 a 元素,而且这个无限深.
The a element can hold a elements and this endlessly deep.
我只是写一个 A 类然后给它一个 List 作为成员吗?那么 JAXB 会自动发挥作用吗?还是这种结构不可能?
Do I just write a class A and then give it a List as a member? JAXB does the magic automatically then? Or is this structure not possible?
推荐答案
是的,你可以拥有以下:
Yes you can have the following:
@XmlAccessorType(XmlAccessType.FIELD) public class A { private List<A> a; }
还有你的 JAXB (JSR-222) 实现将正确编组它.
And your JAXB (JSR-222) implementation will marshal it correctly.
相关示例
- 如何解组xml消息父/子模型不好