2
我正在使用JAXB解組XML文件。 這裏是我的元素特徵代碼,但我想在該元素的特徵元素的特殊訂貨,這樣JAXB和財產訂購與元素列表
<feature>
<name>2D Polynomial Approximation of Log of ConstantQ</name>
<active>false</active>
<attribute>50</attribute>
<attribute>20</attribute>
<attribute>10</attribute>
<attribute>10</attribute>
</feature>
我查@XmlType的一些教程(propOrder = {}),但我找不到像這裏的屬性元素這樣的元素列表進行排序的方法。
這裏是我的代碼
@XmlRootElement(name = "feature")
@XmlType(propOrder = {"name", "active","attribute"})
public class Feature{
String name;
boolean active;
List<String> attributes = new LinkedList<String>();
/**
* name element of feature element
* @return
*/
@XmlElement(name = "name")
public final String getName(){
return this.name;
}
public final void setName(String name){
this.name = name;
}
/**
* active element
* @return
*/
@XmlElement(name = "active")
public final boolean getActive(){
return this.active;
}
public final void setActive(boolean active){
this.active = active;
}
/**
* attribute elements
* @return
*/
@XmlElement(name = "attribute")
public final List<String> getAttributes(){
return this.attributes;
}
public final void setAttributes(List<String> attributes){
this.attributes = attributes;
}
}
它總是拋出異常,因爲我只在propOrder定義一個屬性。但由於屬性是多個,可能是一個或多個,我沒有任何想法來實現它。 或者你知道一些其他的方式來訂購的元素提前
嘿,布萊斯,Thnks,你能解釋一下我關於如何實現它的更多細節? – ZYJ
@ZYJ - 我已經添加了您需要更改'propOrder'的內容。 –
啊,好的,我明白了,非常感謝 – ZYJ