tags:

views:

9

answers:

1

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 cumbersome. So am I missing something?

+1  A: 

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>
Jens Granlund
Knew it was simple. I had tried sequence of choices, and for some reason hadn't thought to switch them at the time. I just implemented this and discovered you had suggested it too.
lief79