UNIQUE
私は、かなり基本的なXSDスキーマにあるいくつかの属性に制約を課そうとしてきました。XMLSpyを使用していて、ノードのTEMPLATE.IDの周りに一意の制約を設定したいと考えています(つまり、ノードが一意であることが重要です)。
私は以下を配置し、以下を試しました:
Secenario 1
<xs:unique name="uniqueviewid">
<xs:selector xpath="./views"/>
<xs:field xpath="@id"/>
</xs:unique>
結果: XSD:OKを検証します。XMLは検証しますが、一意の制約を支持しません(つまり、同じIDを持つ2つ以上の要素が取得されません
シナリオ2
<xs:unique name="uniqueviewid">
<xs:selector xpath="views"/>
<xs:field xpath="@id"/>
</xs:unique>
**結果*シナリオ1と同じ。XSDは検証し、XMLは検証しますが@id
、ビュー要素の重複を無視します。
シナリオ3
<xs:unique name="uniqueviewid">
<xs:selector xpath="*"/>
<xs:field xpath="@id"/>
</xs:unique>
結果:XSDValidatesとXMLValidatsは、UNIQUE制約を尊重します(つまり、重複するビューが@id
設計どおりに無効化をスローする場合)。
問題は、ワイルドカードが「*」であるということです。これは、VIEWPODSの下のすべてのサブノードが検証されることを意味しますが、これは私が望んでいることではありません。代わりに、制約をVIEWPOS / VIEWS /@IDの正確なパスに集中させたいと思います。
私のXPATHはすべて間違っていると思いますが、私が特に間違っていることを考えることができませんか?
XMLの例。
これはXMLの例です。
<config xmlns="http://tempuri.org/RIAGenicConfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tempuri.org/RIAGenicConfig.xsd RIAGenicConfig.xsd">
<view>
<viewpods>
<views id="view1"/>
<views id="view1"/>
</viewpods>
</view>
</config>
問題のXSD。
<xs:schema xmlns="http://tempuri.org/RIAGenicConfig.xsd" xmlns:mstns="http://tempuri.org/RIAGenicConfig.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://tempuri.org/RIAGenicConfig.xsd" elementFormDefault="qualified" id="RIAGenicConfig">
<xs:element name="config">
<xs:complexType>
<xs:sequence>
<xs:element name="view">
<xs:complexType>
<xs:choice>
<xs:element name="viewpods">
<xs:complexType>
<xs:choice>
<xs:element name="views" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id"/>
</xs:complexType>
</xs:element>
<xs:element name="blah"/>
</xs:choice>
</xs:complexType>
<xs:unique name="uniqueviewid">
<xs:selector xpath="*"/>
<xs:field xpath="@id"/>
</xs:unique>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>