【问题标题】:xml schema using unique with basesxml 模式使用唯一的基础
【发布时间】:2017-04-19 05:26:14
【问题描述】:

我有几种使用 base="" 标识符相互扩展的数据类型。它们最终都从一种具有 ID 节点的基本类型扩展而来。我希望架构能够查看所有元素,以确保每个元素的 ID 都是唯一的。

到目前为止,我有:

<effects>
  <ResistanceModificationEffect>
    <ID>fire_resistance</ID>
    <!-- other stuff -->
  </ResistanceModificationEffect>
  <ResistanceModificationEffect>
    <ID>fire_resistance</ID>
    <!-- other stuff -->
  </ResistanceModificationEffect>
</effects>

和架构:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema 
 xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="effects">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="ResistanceModificationEffect" type="resistanceModificationEffectDef" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
<xs:unique name="uniqueID">
  <xs:selector xpath=".//*"/>
  <xs:field xpath="@ID"/>
</xs:unique>
</xs:element>

</schema>

至于 xs:unique 元素,我尝试了各种不同的方法,以使其将具有标签 ID 的节点视为检查唯一性的节点。

  <xs:selector xpath="*"/>
  <xs:selector xpath="./*"/>
  <xs:selector xpath=".//*"/>

从我所读过的关于模式的所有内容中,我只需要

  <xs:selector xpath="*"/>

除非我只是不理解它。 This 链接在底部说“*”是选择所有子项时的有效标识符,“@elementName”应该选择要比较的元素。

我误会了什么?

【问题讨论】:

    标签: xml xsd schema unique base


    【解决方案1】:

    面部护理

    使用我上面提供的链接回答了我自己的问题。使用

      <xs:field xpath="@ID"/>
    

    尝试从所选节点获取属性

      <xs:field xpath="ID"/>
    

    给出正确的错误信息。我专注于错误的事情......

    【讨论】:

      猜你喜欢
      • 2012-04-23
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-05
      相关资源
      最近更新 更多