开发者

Is it possible to alternate between two types in an XML Schema

I'm wondering if I am missing something obvious.

I have a list of numbers, possibly including ranges (think of the print page option of a print dialog).

Ideally I'd like to have the final XML output look like this, with page and pageRange in an order.

  <pages>
 <page> 1</page>
   <pageRange><start>3</start><end>6</end></pageRange>
   <page> 34</page>
</pages>

What would I have to put into a schema to allow this?

From what I saw: Sequence with multiple page and page Range allowed doesn't permit alternation. Choice only allows one or the other.

I tried messing with all, but I wasn't getting it to validate properly.

My short term solution is to have a sequence of ranges, and to force single numbers into the range, but it seems potentially cum开发者_StackOverflowbersome. So am I missing something?


try this...

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="pages">
    <xs:complexType>
      <xs:sequence>
        <xs:choice maxOccurs="unbounded">
          <xs:element name="page" type="xs:unsignedInt" />
          <xs:element name="pageRange">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="start" type="xs:unsignedInt" />
                <xs:element name="end" type="xs:unsignedInt" />
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜