2

XSDスキーマにフィールドがありました:

<xs:element name="magicField">
    <xs:simpleType>
        <xs:restriction base="xs:int">
            <xs:totalDigits value="8"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

Java クラスでは、フィールドが生成されました。

int magicField;

しかし、その後、xsd スキーマは次のように変更されました。

<xs:element name="magicField">
    <xs:complexType>
        <xs:simpleContent>
            <xs:restriction base="int_code">
                <xs:totalDigits value="8"/>
            </xs:restriction>
        </xs:simpleContent>
    </xs:complexType>
</xs:element>

ここで「int_code」:

<xs:complexType name="int_code">
    <xs:simpleContent>
        <xs:extension base="xs:positiveInteger">
            <xs:attribute name="name"/>
        </xs:extension>
    </xs:simpleContent>
</xs:complexType>

また、JAXB は次のコードを生成します。

MagicField magicField;

および MagicField.java が追加されています。

しかし、私はまだ必要です

int magicField;

生成されたコードで。
属性「名前」はまったく使用されません。

スキーマを変更できません。バインド ファイル (xjb) のみを使用しています。

「int_code」タイプを再マップし、「magicField」をintcomplexType (コード内) ではなく simpleType (コード内)として取得するバインディングを作成するにはどうすればよいmagicFieldですか?

私が理解しているように、バインディング ルールだけでなく、カスタム XmlAdapter も必要です。

前もって感謝します。

4

1 に答える 1

0

複合型 int_code を作成する代わりに、以下を使用できます。

<xs:element name="magicField">
<xs:complexType>
    <xs:simpleContent>
        <xs:restriction base="xs:positiveInteger">
            <xs:totalDigits value="8"/>
        </xs:restriction>
    </xs:simpleContent>
</xs:complexType>

または、以下のように magicField の simpleType を作成するより良い方法:

   <xs:element name="magicField">
    <xs:simpleType>
        <xs:restriction base="xs:positiveInteger">
            <xs:totalDigits value="8" />
        </xs:restriction>
    </xs:simpleType>
</xs:element>

お役に立てれば。

于 2014-02-25T11:02:54.367 に答える