3

我想知道是否可以区分 XML 模式中的 ID 字段。我有以下架构:

<element name="define_apple">
    <complexType>
        <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>

然而,参考文献并没有唯一地链接到各自的定义。我仍然可以编写以下废话但有效的 XML:

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

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

有没有办法使用 ID 和 IDREF 正确链接字段,例如使用命名空间?我知道我可以只使用 key 和 keyref,但是 ID 对我来说更有吸引力。

4

1 回答 1

1

不,我不认为这是可能的。http://www.w3.org/TR/xmlschema-2/#IDhttp://www.w3.org/TR/xmlschema-2/#IDREF说 ID 和 IDREF 属性类型来自 XML 标准,而http://www.w3.org/TR/2000/WD-xml-2e-20000814#NT-TokenizedType表示 IDREF 的有效性约束仅匹配文档中的某个 ID。我猜 ID 和 IDREF 主要是在 XML Schema 中,以便与 DTD 向后兼容。

于 2011-08-31T09:58:35.760 回答