开发者

Xml Schema: How to define a key / keyref for different elements in same group?

I have this part of my xsd:

<!-- 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>

All of those element types (textfield-type, numberfield-type, button-type) extend the common type 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>

I now want to create a Key that is unique among all elements directly within the FieldGroup - no matter which element they actually are, and be able to reference them from some elements in the FieldValidationGroup.

Or: how can I define the key on the field-type so that it is derived to all other elements extending the field-type?

As you can see I currently have an ID there, but the ID is also unique among all other elements not in the field group and that could lead to wrong references.

How can I achieve this?


Based on your general approach that relies on reuse - through xsd:group and type hierarchies - I infer that you want to be able to "reuse" key definitions as well. If true, then the short answer is it cannot be done. key, keyref, and unique a.k.a identity constraint definition schema components, can only be nested within element declarations. One cannot define a key related to a xsd:group so that it'll work "no matter which elements they actually are", nor "define a key" on a type "so that is is derived to all other elements."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜