【问题标题】:Restricting children of an XSD element to be of a certain complexType将 XSD 元素的子元素限制为某个 complexType
【发布时间】:2011-07-22 07:17:07
【问题描述】:

我有一个结构如下的 XML 文档:

<document>
    <!-- heading is an element of complexType ns:blockType -->
    <heading>
    </heading>

    <!-- so is paragraph -->
    <paragraph>
    </paragraph>

    <!-- foo, in another namespace, is also of complexType ns:blockType -->
    <otherNS:foo>
    </otherNS:foo>
</document>

如何将document 的子级限制为blockType 类型?

【问题讨论】:

    标签: xml xsd xml-namespaces


    【解决方案1】:

    你可以定义

    <xs:element name="block" abstract="true" type="ns:blockType"/>
    

    <xs:complexType name="headingType">
      <xs:sequence>
        <xs:element ref="block" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
    

    这允许标题包含“block”替换组中的任何元素,并且元素只有在其类型为 ns:blockType 时才能在此替换组中。

    这不是你要求的,但这是我能得到的最接近的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-10
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多