如何在JAXB中向文本元素添加属性?

时间:2010-12-01 16:28:31

标签: java xml jaxb

如何使用JAXB生成以下XML片段?

<sequence md5="1de2cf633901ff1f00785735c8ce7e70">MPTINSALRKVARVRLTSG</sequence>

我的课程如下:

@XmlType(name = "SequenceType")
public class Sequence {

    private String md5;
    private String sequence;

    @XmlAttribute
    public String getMd5() {
        return md5;
    }

    // JAXB annotation here??
    public String getSequence() {
        return sequence;
    }

}

1 个答案:

答案 0 :(得分:14)

序列属性上的@XmlValue。

@XmlType(name = "SequenceType")
public class Sequence {

    private String md5;
    private String sequence;

    @XmlAttribute
    public String getMd5() {
        return md5;
    }

    @XmlValue
    public String getSequence() {
        return sequence;
    }

}