以下は、ユース ケースの XML 構造を定義する XML スキーマです。
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/schema"
xmlns:tns="http://www.example.org/schema" elementFormDefault="qualified">
<element name="elem">
<complexType>
<simpleContent>
<extension base="string">
<attribute name="attr" type="string" />
</extension>
</simpleContent>
</complexType>
</element>
</schema>
この XML スキーマから JAXB モデルを生成すると、次のクラスが生成されます。
package forum12859885;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlValue;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"value"
})
@XmlRootElement(name = "elem")
public class Elem {
@XmlValue
protected String value;
@XmlAttribute(name = "attr")
protected String attr;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getAttr() {
return attr;
}
public void setAttr(String value) {
this.attr = value;
}
}