私は xjc を使用して XML スキーマから Java クラスを生成しています。以下は XSD の抜粋です。
<xs:element name="NameInfo">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element ref="UnstructuredName"/> <!-- This line -->
<xs:sequence>
<xs:element ref="StructuredName"/>
<xs:element ref="UnstructuredName" minOccurs="0"/> <!-- and this line! -->
</xs:sequence>
</xs:choice>
<xs:element ref="SomethingElse" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
ほとんどの場合、生成されたクラスは問題ありませんが、上記のブロックでは次のようになります。
public List<Object> getContent() {
if (content == null) {
content = new ArrayList<Object>();
}
return this.content;
}
その上に次のコメントを付けます。
* You are getting this "catch-all" property because of the following reason:
* The field name "UnstructuredName" is used by two different parts of a schema. See:
* line XXXX of file:FILE.xsd
* line XXXX of file:FILE.xsd
* To get rid of this property, apply a property customization to one
* of both of the following declarations to change their names:
* Gets the value of the content property.
問題の 2 行の最後にコメントを入れました。
現時点では、スキーマを変更するのは簡単ではないと思います。これはベンダー間で決定されたものであり、進行がかなり遅くなるため、(可能であれば) このルートには行きたくありません。
検索したところ、このページを見つけました。外部カスタマイズは私がやりたいことですか? 私は主に生成されたクラスを扱ってきたので、これらのクラスを生成するプロセスに完全に精通しているわけではありません。「プロパティのカスタマイズ」の簡単な例は素晴らしいでしょう! Java クラスを生成する別の方法は、スキーマを使用できる限り問題ありません。
UnstructuredName
編集:2つが実際に同じ要素であることを明確にする必要があります。