XSD complexType definition without indicators

422 Views Asked by At

if i want to define a complex type, i can go

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

or, i can replace the

<xs:sequence> ...     </xs:sequence>

tag in the above with

<xs:all> ...     </xs:all>

or

<xs:choice> ...     </xs:choice>

and it validates.

However, these are imposing restrictions on the order/occurrence of the elements.

Is there a way to define a complex element without any of these indicators?

Been "inspired" with

<xs:complexType name="personinfo2">
<xs:complexContent>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:complexContent>
</xs:complexType>

so far, but didn't work.

1

There are 1 best solutions below

0
On

You really should read a tutorial on XSD.

No, you cannot define a content model without specifying (explicitly or implicitly) one of xs:sequence, xs:choice, or xs:all.

If you want to make no restrictions on the sequence or number of occurrences of your child elements, then what you probably want is:

<xs:complexType name="sample">
  <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element name="e1" type="xs:string"/>
    <xs:element name="e2" type="xs:string"/>
  </xs:choice>
</xs:complexType>

This allows any number of e1 and e2 children, in any order. If you find that you don't want any valid elements of type personinfo to contain 37 lastname elements and 36 firstname elements, in alternation, then you have discovered something about what you do and don't want.