2

私は XSD スキーマを作成して、特に多数のresult要素を格納するドキュメントを検証しています。この要素の 2 つの属性clickIndextimeViewedはオプションであり、組み込みのデータ型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 ファイルを処理して統計情報を生成します。属性が欠落していると、不要な複雑さが生じる可能性があります。これに対する回避策がない場合は、空の値をゼロに置き換えます。きれいに見えるので、空の文字列を保持することをお勧めしますが、おそらくゼロもより効率的です。

4

1 に答える 1

2

問題の属性が整数型の場合、空の文字列を割り当てることはできません。引用符内の値は、整数に解析できる必要があります。あなたが言ったようにゼロ値でxmlを更新するか、空の文字列値を保持する属性を削除する必要があります。これらのソリューションのいずれも好まない場合は、独自のカスタム タイプを定義する必要があります。詳細については、これを参照してください。

XSD 属性を null 可能にする

于 2013-04-30T09:23:49.197 に答える