【问题标题】:Referencing multiple IDs in an XML schema (XSD)在 XML 模式 (XSD) 中引用多个 ID
【发布时间】:2011-11-07 11:16:06
【问题描述】:

我想知道是否可以区分 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 对我来说更有吸引力。

【问题讨论】:

    标签: xml namespaces xsd schema validating


    【解决方案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-02-07
      • 2014-07-13
      • 1970-01-01
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-19
      • 1970-01-01
      相关资源
      最近更新 更多