ソース コード (複数言語) のジェネレーターを作成する予定です。クラス、つまり基本的なデータ コンテナーは、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
属性で定義された識別子を許可する方法はありますか、それともジェネレーター内で許可して有効性を確認する必要がありますか?customType
xsd:string
編集
W3C XML スキーマ定義言語 (XSD) 勧告の 3.16.2を正しく
理解していれば、XSD を使用して必要なことを実行することはできません (制限はminExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern | assertion | explicitTimezone
、この種の動的制限をサポートしていない に限定されているため)。これは、XSD スキーマを手動で検証した後です。
これが正しいことを誰でも確認できますか?