2011-08-19 62 views
2

我有我的xsd的這一部分:Xml架構:如何爲同一組中的不同元素定義鍵/ keyref?

<!-- FIELDGROUP - groups all available field types --> 
<xsd:group name="FieldGroup"> 
    <xsd:choice id="fieldset-fields"> 
     <xsd:element name="TextField" type="textfield-type" maxOccurs="unbounded" /> 
     <xsd:element name="NumberField" type="numberfield-type" maxOccurs="unbounded" /> 
     <xsd:element name="Button" type="button-type" maxOccurs="unbounded" /> 
    </xsd:choice> 
</xsd:group> 

所有這些元素類型(文本字段類型,numberfield型,鈕釦型)的延長普通型field-type

<!-- Fieldset -> FIELD-TYPE: the base type of all possible field elements --> 
<xsd:complexType id="field-type" name="field-type" abstract="true" mixed="false"> 
    <xsd:sequence> 
     <xsd:element name="Label" type="label-type" minOccurs="0" maxOccurs="1" /> 
     <xsd:group ref="FieldValidationGroup" /> 
    </xsd:sequence> 

    <xsd:attribute id="field-type-id" name="id" type="id-type" use="required" /> 
    <xsd:attribute id="field-type-css-class" name="css-class" use="optional" type="css-class-type" /> 
</xsd:complexType> 

我現在想要創建一個在FieldGroup之內的所有元素中唯一的密鑰 - 無論他們實際上是哪個元素,並且能夠從FieldValidationGroup中的某些元素引用它們。

或者:我如何定義field-type上的密鑰,以便將其派生到擴展字段類型的所有其他元素?

正如你所看到的,我目前有一個ID,但ID在所有其他元素中也是唯一的,而不是在字段組中,這可能導致錯誤的引用。

我該如何做到這一點?

回答

3

根據您通用的方法,依靠重用 - 通過xsd:組和類型層次結構 - 我推斷您也希望能夠「重用」鍵定義。如果屬實,那麼簡短的答案是不能做到的。 keyref,和獨特 a.k.a 同一性約束定義的模式組件,只能被嵌套元素聲明內。我們無法定義與xsd:group相關的關鍵字,這樣它就可以「無論它們實際上是哪些元素」,也不需要在類型上定義一個「關鍵字」,這樣就可以派生到所有其他元素。「

+0

傷心,不可能做這樣的事情。能夠這樣做會感覺很直觀。 –

相關問題