Zeus
Zeus

Reputation: 6566

Array of string in XSD

Hello I need to show the array of strings in XSD. I've tried this, Can any one help me write it correctly. Thanks.

What it prints

<numbers>13 32 23</numbers>

Current XSD

<xs:element name="numbers" minOccurs="0" maxOccurs="1"> 
    <xs:simpleType>
          <xs:list itemType="xs:string">                                                     

          </xs:list>
    </xs:simpleType>

What I need is below.

<numbers>
   <number>13</number><number>32</number>
</numbers>

Upvotes: 3

Views: 33683

Answers (2)

Ignacio Alorre
Ignacio Alorre

Reputation: 7605

The question is resolved since Petru's answer is correct. I just want to add some additional information I found related with this same topic about how to define array types, optional and mandatory:

Primitive types

 <xsd:element name="A"/>

means A is required and must appear exactly once.

<xsd:element name="A" minOccurs="0"/>

means A is optional and may appear at most once.

Arrays/Lists

<xsd:element name="A" maxOccurs="unbounded"/>

means A is required and may repeat an unlimited number of times

<xsd:element name="A" minOccurs="0" maxOccurs="unbounded"/>

means A is optional and may repeat an unlimited number of times

Upvotes: 10

Petru Gardea
Petru Gardea

Reputation: 21638

You can start with this:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="numbers">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="number" type="xs:unsignedByte"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

numbers would be a complex typed-element, accepting element only content.

Upvotes: 9

Related Questions