Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have complexType and elements inside but without the sequence part

Tags:

xml

sequence

I hava a xml doc (and complex element) that is similar to this example:

<xs:element name="employee">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="firstname" type="xs:string"/>
   <xs:element name="lastname" type="xs:string"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

But in my xml it shouldn't matter if I add firstname or lastname first. So I would like to remove the "xs:sequence" part but I am not sure what I should replace it with.

If it is not possible - then why is it not possible?

Update: If I change it with < cx:all> I get this error: "The {max occurs} of all the {parties} of an all group must be 0 or 1".

like image 523
Imageree Avatar asked Nov 12 '09 14:11

Imageree


2 Answers

Use <xs:all> instead of <xs:sequence>:

<xs:element name="employee">
 <xs:complexType>
  <xs:all>
   <xs:element name="firstname" type="xs:string"/>
   <xs:element name="lastname" type="xs:string"/>
  </xs:all>
 </xs:complexType>
</xs:element>

See the W3Schools page on the schema indicators:

All Indicator

The <all> indicator specifies that the child elements can appear in any order, and that each child element must occur only once:

like image 108
marc_s Avatar answered Sep 30 '22 01:09

marc_s


<xs:element name="employee">
    <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="firstname" type="xs:string" />
            <xs:element name="lastname" type="xs:string" />
        </xs:choice>
   </xs:complexType>
</xs:element>

This will allow you to have elements in any sequence and quantity.

like image 22
Neil Bryson Avatar answered Sep 30 '22 01:09

Neil Bryson