我想从 javabean 制作 xml,如下所示:
<tag2>message</tag2>
<tag3>message</tag3>
<tag4 id='UNIQUE MT ID 1'>MOBILE No.</tag4>
我在javabean中尝试了以下代码:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "name", propOrder = {"tag2", "tag3", "tag4"})
public class newBean {
@XmlElement(required = true)
private List<String> tag2;
@XmlElement(required = true)
private List<String> tag3;
@XmlElement(required = true)
private List<String> tag4;
@XmlPath("tag4/@id")
private List<String> id;
public List<String> getTag2() {
return tag2;
}
public void setTag2(List<String> tag2) {
this.tag2 = tag2;
}
public List<String> gettag4() {
return tag4;
}
public void settag4(List<String> tag4) {
this.tag4 = tag4;
}
public List<String> getId() {
return id;
}
public void setId(List<String> identifier) {
this.id = identifier;
}
public List<String> gettag3() {
return tag3;
}
public void settag3(List<String> tag3) {
this.tag3 = tag3;
}
}
我收到以下错误:
Errorcom.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Property id is present but not specified in @XmlType.propOrder
this problem is related to the following location:
at private java.util.List model.newBean.id
at model.newBean
请帮助我。我正在使用@XmlPath 标签并生成错误。我搜索了很多,发现@XmlPath 的用法与我使用的上面相同,但仍然出现错误。