开发者

XML Schema for type that can contain zero or more 'x' elements and zero or one 'y' element anywhere?

I want my element, called subquery to be able to contain zero or more insert elements, and zero or one subquery element. These elements can be anywhere. These would be valid subquery elements:

<subquery>
    <subquery>...</subquery>
</subquery>

<subquery>
    <insert />
    <insert />
</subquery>

<subquery>
    <insert />
    <subquery>...</subquery>
    <insert />
</subquery>

<subquery>
    <s开发者_如何学运维ubquery>...</subquery>
    <insert />
    <insert />
</subquery>

<subquery>
    <insert />
    <insert />
    <insert />
    <subquery>...</subquery>
</subquery>

I've tried many ways but can't get a valid schema to work. When I use maxOccurs="unbounded" for insert's type inside an All, Liquid XML Studio tells me maxOccurs must be 0 or 1. Can't get it to work as a sequence either.

Is this even possible?


Wouldn't this model do it?: insert* (subquery, insert*)?

  <xs:element name="subquery">
    <xs:complexType>
      <xs:sequence>
         <xs:element ref="insert" minOccurs="0" maxOccurs="unbounded"/>
         <xs:sequence minOccurs="0">
            <xs:element ref="subquery"/>
            <xs:element ref="insert" minOccurs="0" maxOccurs="unbounded"/>
         </xs:sequence>
      </xs:sequence>
    </xs:complexType>
  </xs:element>


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="subqueries">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="subquery"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="subquery">
    <xs:complexType mixed="true">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="subquery"/>
        <xs:element ref="insert"/>
      </xs:choice>
    </xs:complexType>
  </xs:element>
  <xs:element name="insert">
    <xs:complexType/>
  </xs:element>
</xs:schema>

This would be sufficient? (I've added a root-element subqueries.)

Cheers, Wim

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜