1

以下のように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の使用法が上記と同じであることがわかりましたが、まだエラーが発生しています.

4

1 に答える 1