当前位置: 动力学知识库 > 问答 > 编程问答 >

java - jaxb: How can I bind nested element

问题描述:

There is my xml:

<parent>

<children>

<child>1</child>

<child>2</child>

</children>

</parent>

I want to have the following Parent class:

@XmlRootElement

Parent{

@XmlElement(name="children/child")

List<Child> children;

}

I don't want to have class for element 'children'.

How should I map field children ?

网友答案:

Use @XmlElementWrapper:

@XmlRootElement
public class Parent {
   @XmlElementWrapper(name="children")
   @XmlElement(name="child") 
   List<Child> children;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: