私は XSD スキーマを作成して、特に多数のresult
要素を格納するドキュメントを検証しています。この要素の 2 つの属性clickIndex
とtimeViewed
はオプションであり、組み込みのデータ型nonNegativeInteger
とを使用しdecimal
ます。値が設定されていないときにこれらの属性を削除する代わりに、次のように空の文字列に設定したいと思います。
<Page resultCount="10" visited="true">
<Result index="1" clickIndex="1" timeViewed="45.21" pid="56118" title="alpha"/>
<Result index="2" clickIndex="" timeViewed="" pid="75841" title="beta"/>
<Result index="3" clickIndex="2" timeViewed="21.45" pid="4563" title="gamma"/>
<Result index="4" clickIndex="" timeViewed="" pid="44546" title="delta"/>
<Result index="5" clickIndex="" timeViewed="" pid="1651" title="epsilo"/>
<Result index="6" clickIndex="" timeViewed="" pid="551651" title="zeta"/>
<Result index="7" clickIndex="" timeViewed="" pid="20358" title="eta"/>
<Result index="8" clickIndex="" timeViewed="" pid="61621" title="theta"/>
<Result index="9" clickIndex="" timeViewed="" pid="135154" title="iota"/>
<Result index="10" clickIndex="" timeViewed="" pid="95821" title="kappa"/>
</Page>
残念ながら、これは次の xsd に対して検証されません。
<xs:element name="Result">
<xs:complexType>
<xs:attribute name="index" type="xs:nonNegativeInteger" use="required"/>
<xs:attribute name="clickIndex" type="xs:nonNegativeInteger" use="optional"/>
<xs:attribute name="timeViewed" type="xs:decimal" use="optional"/>
<xs:attribute name="pid" type="xs:positiveInteger" use="required"/>
<xs:attribute name="title" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
定義されたタイプの属性で空の文字列を検証することは不可能ですか? カスタムタイプを定義せずにこれを行う方法はありますか? XSD のオプションを忘れているだけですか?
これらの XML ファイルを処理して統計情報を生成します。属性が欠落していると、不要な複雑さが生じる可能性があります。これに対する回避策がない場合は、空の値をゼロに置き換えます。きれいに見えるので、空の文字列を保持することをお勧めしますが、おそらくゼロもより効率的です。