私のプロジェクトで既存のXMLファイルの一部を検証しようとしています。例えば、構造は次のようになります。すなわちユニークなパーティクルエラー、任意の順序で複数の子要素を許可したい
<resources>
<file name="one" path="C:\test\one.txt" />
<cache path="C:\test\cache\" />
<file name="two" path="C:\test\two.txt" />
<bundle name="myFolder">
<file name="three" path="C:\test\three.txt" />
<file name="four" path="C:\test\four.txt" />
</bundle>
<file name="one" path="C:\test\one.txt" />
<bundle name="myFolder">
<file name="three" path="C:\test\three.txt" />
<file name="four" path="C:\test\four.txt" />
</bundle>
<file name="one" path="C:\test\one.txt" />
</resources>
、私が欲しいのは、任意の数の任意の順序
- で最も1つの
cache
要素を持つルート要素resources
、との構造であり、file
およびbundle
要素の任意の順序で、 bundle
には、任意の数のfile
要素が含まれます。
これは(this answerから描画)私の現在のXSDです:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="cache">
<xs:attribute name="path" type="xs:string" />
</xs:complexType>
<xs:complexType name="file">
<xs:attribute name="name" type="xs:string" />
<xs:attribute name="path" type="xs:string" />
</xs:complexType>
<xs:complexType name="bundle">
<xs:choice maxOccurs="unbounded">
<xs:element name="file" type="file" maxOccurs="unbounded" />
</xs:choice>
<xs:attribute name="type" />
<xs:attribute name="name" />
</xs:complexType>
<xs:group name="unboundednoncache">
<xs:choice>
<xs:element name="file" type="file" />
<xs:element name="bundle" type="bundle" />
</xs:choice>
</xs:group>
<xs:element name="resources">
<xs:complexType>
<xs:sequence>
<!-- Validates if this next line is removed,
and the cache element is moved to first -->
<xs:group ref="unboundednoncache" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="cache" type="cache" minOccurs="0" maxOccurs="1" />
<xs:group ref="unboundednoncache" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
これは私にエラーを与える:
Cos-nonambig: File And File (or Elements From Their Substitution Group) Violate "Unique Particle Attribution". During Validation Against This Schema, Ambiguity Would Be Created For Those Two Particles.
私が最初<xs:group>
を削除する場合、私は検証する最初のXSDを取得することができますXSDでcache
要素をXMLの最初の子に移動しますが、キャッシュ要素はどこでも有効です。
(これより前のバージョンに私が使っていた:私はどちらかしたくない複数のキャッシュ・エレメントを、
<xs:choice maxOccurs="unbounded">
<xs:element name="cache" type="cache" minOccurs="0" maxOccurs="1" />
<xs:element name="file" type="file" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="bundle" type="bundle" minOccurs="0" maxOccurs="unbounded" />
</xs:choice>
..しかし、それはできます)
はなぜ私のXSDは違反しない「ユニークな粒子私はそれをどのように修正することができますか?あなたのスキーマ文書で