XSD要素があります
<xsd:element name="author" type="cmd:Author" nillable="true">
<xsd:annotation>
<xsd:documentation>Contains author name and author id
</xsd:documentation>
</xsd:annotation>
</xsd:element>
タイプの作者:
<xsd:complexType name="Author">
<xsd:annotation>
<xsd:documentation>Author's name and id.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:extension base="cmd:AuthorName">
<xsd:attribute name="id" type="cmd:Id" use="optional">
<xsd:annotation>
<xsd:documentation>Author's Id
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
ベースの作成者名:
<xsd:simpleType name="AuthorName">
<xsd:annotation>
<xsd:documentation>Type defining author's name.
It may contain characters from AllowedChars
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="cmd:AllowedChars">
<xsd:maxLength value="112"/>
</xsd:restriction>
</xsd:simpleType>
タイプ ID:
<xsd:simpleType name="Id">
<xsd:annotation>
<xsd:documentation>Id
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{6}"/>
</xsd:restriction>
</xsd:simpleType>
問題は、常に ID を持っていることですが、AuthorName が null になることがあります。
その状況で私が得るものは次のとおりです。
<author id="111111"/>
私が取得したいものは次のとおりです。
<author id="111111"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:nil="true"/>
私の実際の状態では、スキーマの互換性に問題があります。XSDモデルを変更せずにやりたいことをすることは可能ですか? Author を AuthorName と AuthorId に分割することは下位互換性がなく、かなり大きなアプリケーションを書き直す必要があります。
追加情報 (何が役に立ち、何が役に立たないのかよくわかりません): アプリケーションは J2E にあり、xsd を JAXB にバインドし、XJC を使用してクラスを生成しています。
生成されたクラスの作成者:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Author", propOrder = {
"value"
})
public class Author implements Serializable
{
@XmlValue
protected String value;
@XmlAttribute(name = "id")
protected String id;
//getters and setters
}