Java JAXB解组不同类型的列表
我有以下xml:Java JAXB解组不同类型的列表,java,xml,jaxb,Java,Xml,Jaxb,我有以下xml: <scope> <heading> <code></code> </heading> <heading> <code></code> </heading> <value> <code></code> </value> <value>
<scope>
<heading>
<code></code>
</heading>
<heading>
<code></code>
</heading>
<value>
<code></code>
</value>
<value>
<code></code>
</value>
</scope>
我该如何去解开这个,这样我就有了两个列表。
谢谢。@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
公共静态类范围{
@xmlement(name=“heading”)
列表标题=新建链接列表();
@xmlement(name=“value”)
列表值=新建LinkedList();
公共范围(){
}
公共列表标题(){
返回标题;
}
公共无效设置标题(列表标题){
这个标题=标题;
}
公共列表getValues(){
返回值;
}
公共void设置值(列表值){
这个值=值;
}
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
公共静态类标题{
私有字符串码;
公共标题(){
}
公共字符串getCode(){
返回码;
}
公共无效设置码(字符串码){
this.code=代码;
}
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
公共静态类值{
私有字符串码;
公共价值(){
}
公共字符串getCode(){
返回码;
}
公共无效设置码(字符串码){
this.code=代码;
}
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public static class Scope {
@XmlElement(name = "heading")
List<Heading> headings = new LinkedList<>();
@XmlElement(name = "value")
List<Value> values = new LinkedList<>();
public Scope() {
}
public List<Heading> getHeadings() {
return headings;
}
public void setHeadings(List<Heading> headings) {
this.headings = headings;
}
public List<Value> getValues() {
return values;
}
public void setValues(List<Value> values) {
this.values = values;
}
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public static class Heading {
private String code;
public Heading() {
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public static class Value {
private String code;
public Value() {
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}