开发者

Restricting children of an XSD element to be of a certain complexType

I have a XML document structued like the following:

<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>

How can I restrict t开发者_如何学运维he children of document to only be of type blockType?


You could define

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

and

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

This allows heading to contain any element in the substitution group of "block", and an element can only be in this substitution group if it has a type of ns:blockType.

That's not quite what you asked for but it's the closest I can get.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜