0

ソース コード (複数言語) のジェネレーターを作成する予定です。クラス、つまり基本的なデータ コンテナーは、XML ファイルとして指定する必要があります。これらの XML ファイルを自動的に検証して解析するために、XSD スキーマを定義しています。これは有効なファイルである必要があります。

<?xml version="1.0"?>
<class>
    <customType name="vector3D">
        <variable name="x" type="int"/>
        <variable name="y" type="int"/>
        <variable name="z" type="int"/>
    </customType>
    <variable name="identifier" type="string"/>
    <variable name="direction" type="vector3D"/>
</class>

ルート要素classと要素customTypeと を次のように定義しvariableました。

<xsd:complexType name="Class">
    <xsd:sequence>
        <xsd:element name="customType" type="CustomType"
            minOccurs="0" maxOccurs="unbounded"/>
        <xsd:element name="variable" type="Variable"
            minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
<xsd:complexType>

<xsd:complexType name="CustomType">
    <xsd:sequence>
        <xsd:element name="variable" type="Variable"
            minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="name" type="xsd:string"
        use="required"/>
</xsd:complexType>

<xsd:complexType name="Variable">
    <xsd:attribute name="name" type="xsd:string"
        use="required"/>
    <xsd:attribute name="type" type="ValidType"
        use="required"/>
</xsd:complexType>

ただし、タグで定義された基本型名前の限定されたセットを許可しようとして、私は非常に苦労しています。customType基本型のセットを定義するのは簡単でした:

<xsd:simpleType name="ValidType">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration value="bool"/>
        <xsd:enumeration value="int"/>
        <xsd:enumeration value="string"/>
    </xsd:restriction>
</xsd:simpleType>

しかし、タグ のname 属性で定義された識別子を許可する方法はありますか、それともジェネレーター内で許可して有効性を確認する必要がありますか?customTypexsd:string

編集

W3C XML スキーマ定義言語 (XSD) 勧告の 3.16.2を正しく 理解していれば、XSD を使用して必要なことを実行することはできません (制限はminExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern | assertion | explicitTimezone、この種の動的制限をサポートしていない に限定されているため)。これは、XSD スキーマを手動で検証した後です。

これが正しいことを誰でも確認できますか?

4

1 に答える 1

3

はい、あなたは正しいと思います。xsd 1.0 では、「属性が XX と等しい場合、属性タイプは ZZ のみと等しい」などの動的制限を作成することはできません。xsd 1.1 では、アサーションを定義する可能性がありますが、利用可能なパーサーでどの程度サポートされているかはわかりません (おそらく、Saxon にはこの機能がある可能性があります)。

于 2013-07-15T13:39:07.887 に答える