开发者

Referencing multiple IDs in an XML schema (XSD)

I was wondering whether it's possible to differentiate between ID fields in an XML schema. I'm having the following schema:

<element name="define_apple">
    <comple开发者_开发问答xType>
        <attribute name="colour" type="ID"/>
    </complexType>
</element>

<element name="define_orange">
    <complexType>
        <attribute name="colour" type="ID"/>
    </complexType>
</element>

<element name="reference_apple">
    <complexType>
        <attribute name="colour" type="IDREF"/>
    </complexType>
</element>

<element name="reference_orange">
    <complexType>
        <attribute name="colour" type="IDREF"/>
    </complexType>
</element>

However, the references are not uniquely linked to the respective definitions. I can still write the following nonsense but valid XML:

<define_apple colour="green"/>
<define_orange colour="orange"/>

<reference_apple colour="orange"/>
<reference_orange colour="green"/>

Is there a way to link the fields correctly using ID and IDREF, for instance using namespaces? I know I could just use key and keyref, but the ID thing is a bit more appealing to me.


No, I don't think this is possible. http://www.w3.org/TR/xmlschema-2/#ID and http://www.w3.org/TR/xmlschema-2/#IDREF say that the ID and IDREF attributes types come from the XML standard, and http://www.w3.org/TR/2000/WD-xml-2e-20000814#NT-TokenizedType says that the validity constraints on IDREF is only to match some ID in the document. I guess ID and IDREF are mostly in XML Schema for backwards compatibility with DTDs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜