2
votes

Is it possible to define a complex type sequence with optional elements followed by n optional any elements? Currently I have this XSD which violaets UPA:

<xs:complexType name="itemtype">
    <xs:sequence>
        <xs:element name="uuid" type="uuidtype"/>
        <xs:element name="lastname" type="nametype"/>
        <xs:element name="isActive" minOccurs="0" type="isactivetype"/>
        <xs:element name="countries_scope" type="countryscopetype"/>
        <xs:element name="origin" minOccurs="0" type="nametype"/>
        <xs:element name="url" minOccurs="0" type="nametype"/>
        <xs:element name="email" minOccurs="0" type="emailtype"/>
        <xs:element name="description" minOccurs="0" type="nametype"/>
        <xs:element name="town" minOccurs="0" type="nametype"/>
        <xs:element name="role" minOccurs="0" type="nametype"/>
        <xs:element name="source" minOccurs="0" type="nametype"/>
        <xs:element name="origin_zip" minOccurs="0" type="nametype"/>
        <xs:element name="town_zip" minOccurs="0" type="nametype"/>
        <xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
    </xs:sequence>
</xs:complexType>

A possible XML could be:

<item>
  <uuid>1</uuid>
  <lastname>Yanick</lastname>
  <country_scope>CHE</country_scope>
  <role>Student</role>
  <age>24</age>
</item>

Here only the optional role is used and age would be one any element.

1

1 Answers

2
votes

The solution is simple. THe last element bevore the any can't be an optional. This XSD would work:

<xs:complexType name="itemtype">
<xs:sequence>
    <xs:element name="uuid" type="uuidtype"/>
    <xs:element name="lastname" type="nametype"/>
    <xs:element name="isActive" minOccurs="0" type="isactivetype"/>
    <xs:element name="origin" minOccurs="0" type="nametype"/>
    <xs:element name="url" minOccurs="0" type="nametype"/>
    <xs:element name="email" minOccurs="0" type="emailtype"/>
    <xs:element name="description" minOccurs="0" type="nametype"/>
    <xs:element name="town" minOccurs="0" type="nametype"/>
    <xs:element name="role" minOccurs="0" type="nametype"/>
    <xs:element name="source" minOccurs="0" type="nametype"/>
    <xs:element name="origin_zip" minOccurs="0" type="nametype"/>
    <xs:element name="town_zip" minOccurs="0" type="nametype"/>
    <xs:element name="countries_scope" type="countryscopetype"/>
    <xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
</xs:sequence>