1
什麼方式JAXB給這種類型的XML轉換XML列表到JAXB
<options>
<option name="name">https://abc.com/</option>
<option name="name2">https://abc.com/</option>
</options>
的我創建了兩個對象類轉換。它不會用數據填充對象,併爲應該設置URL的標記設置空值,如https://abc.com/。
Options.java
和Option.java
Options
類包含此setter
@XmlElement(name = "option")
public void setOption(List<Option> option) {
this.option = option;
}
Option.java類是:
@XmlRootElement(name = "option")
public class Option {
String name;
String option;
public Option() {
super();
}
public Option(String name, String option) {
super();
this.name = name;
this.option = option;
}
public String getName() {
return name;
}
@XmlAttribute
public void setName(String name) {
this.name = name;
}
public String getOption() {
return option;
}
public void setOption(String option) {
this.option = option;
}
請關注此:http://stackoverflow.com/questions/3284786/java-jaxb-unmarshall-xml-attributes-to-specific-java-object-attributes –