2012-03-01 58 views
9

我有一個簡單的XML結構:XML架構獨特一起上兩個屬性

<foo> 
    <bar row="42" column="2"></bar> 
    <bar row="42" column="3"></bar> 
</foo> 

我想rowbarcolumn是唯一的一起。所以,上面的例子驗證,而以下不:

<foo> 
    <bar row="42" column="2"></bar> 
    <bar row="42" column="3"></bar> 
    <bar row="42" column="3"></bar> 
</foo> 

我一直在嘗試添加一鍵下面的架構,但我還沒有找到一個解決辦法。

<xs:element name="foo"> 
    <xs:complexType> 
     <xs:sequence> 
      <xs:element name="bar" minOccurs="1" maxOccurs="unbounded"> 
       <xs:complexType> 
        <xs:simpleContent> 
         <xs:extension base="xs:string"> 
          <xs:attribute name="row" type="xs:positiveInteger" use="required"/> 
          <xs:attribute name="column" type="xs:positiveInteger" use="required"/> 
         </xs:extension> 
        </xs:simpleContent> 
       </xs:complexType> 
      </xs:element> 
     </xs:sequence> 
    </xs:complexType> 
</xs:element> 

回答

10

我期待以下事情做到這一點。

<xsd:element name="foo"> 
    ... 
    <xsd:unique name="rowcol"> 
    <xsd:selector xpath="bar"/> 
    <xsd:field xpath="@row"/> 
    <xsd:field xpath="@column"/> 
    </xsd:unique> 
</xsd:element> 

的唯一性contraint無二唯一性範圍的元素聲明,這是我推測是foo內部。如果您的結構實際上更像是:

<root> 
    <foo> ... </foo> 
    <foo> ... </foo> 
</root> 

你想要的獨特性是全球性的,那麼約束應該去root