简体   繁体   中英

How can I add an attribute to a text element in JAXB?

How can I produce the following XML fragment using JAXB?

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

My class is as follows:

@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;
    }

}

@XmlValue on the sequence property.

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

    private String md5;
    private String sequence;

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

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM