对complexType而不是元素的唯一约束

Oli*_*ire 7 xsd

我有以下XSD结构:

<xs:schema xmlns:ns="http://abc/">
  ...
  <xs:element name="abc">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="map"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  ...
  <xs:element name="map">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="entry" type="ns:MapEntryType" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
    <xs:unique name="entry">
      <xs:selector xpath="entry"/>
      <xs:field xpath="key"/>
    </xs:unique>
  </xs:element>
  <xs:complexType name="MapEntryType">
    <xs:sequence>
      <xs:element name="key" type="xs:string"/>
      <xs:element name="value" type="xs:anyType"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

这是在做它的工作.

map现在必须根据包装器中的元素调用该元素,因此有时map,有时properties,有时options等名称.

因此,我想要对该map元素进行泛化.

我尝试过以下操作:

  • 制作map一个xs:complexType和变化reftype.
    • 这导致xs:unique不被接受和失败
  • 制作map一个xs:complexType,换reftype和移动xs:unique约束的元素定义.
    • 这有效但导致XSD xs:unique在文档中有很多内容.

有没有办法简单地告诉我想要一个特定的结构,它包含独特的元素,而不必在任何地方重复独特的约束?

Pet*_*dea 3

简短的回答,这是不可能的。XSD 1.0 和 1.1 都将身份约束置于元素下;约束不能全局定义,因此除了封闭元素之外,本身没有“重用”。鉴于您的场景(不同的需求使用不同的元素名称),不可能重用。