title: Conditional required elements in an XSD
body: <p>I have a requirement for an xml schema which accepts either a request with the customer or with the customer id.  If the customer Id is 0 then we need the customer data, if it's > 0 then customer data is optional (They can submit ammendements).  My XSD looks like this at the moment;</p>
  
  <p></p>
  
  <pre><code>&lt;xs:complexType&gt;
  
  
      &lt;xs:any&gt;
        &lt;xs:element name="UserID" type="xs:string" minOccurs="1"/&gt;
        &lt;xs:element name="Password" type="xs:string" minOccurs="1"/&gt;
        &lt;xs:element name="ReferenceNumber" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="CustomerId" minOccurs="1" maxOccurs="1" type="xs:integer"/&gt;
        &lt;xs:element ref="WhereSigned"/&gt;
        &lt;xs:element name="ContactName" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="ContactTelephone" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="ContactFax" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="ContactEmail" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element ref="MainApplicant"  maxOccurs="1"/&gt;
        &lt;xs:element ref="JointApplicant" minOccurs="0" maxOccurs="1"/&gt;
        &lt;xs:element ref="Asset" minOccurs="0" maxOccurs="1"/&gt;
      &lt;/xs:any&gt;
  
  
  &lt;/xs:complexType&gt;
  </code></pre>
  
  <p></p>
  
  <p>I need something a bit like this... (I wish it were this simple but alas not..)</p>
  
  <p></p>
  
  <pre><code>&lt;xs:complexType&gt;
    &lt;xs:choice&gt;
  
      &lt;xs:any&gt;
        &lt;xs:element name="UserID" type="xs:string" minOccurs="1"/&gt;
        &lt;xs:element name="Password" type="xs:string" minOccurs="1"/&gt;
        &lt;xs:element name="ReferenceNumber" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="CustomerId" minOccurs="1" maxOccurs="1"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:integer"&gt;
              &lt;xs:minInclusive value="0"/&gt;
              &lt;xs:maxInclusive value="0"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:element&gt;
        &lt;xs:element ref="WhereSigned"/&gt;
        &lt;xs:element name="ContactName" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="ContactTelephone" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="ContactFax" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="ContactEmail" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element ref="MainApplicant"  maxOccurs="1"/&gt;
        &lt;xs:element ref="JointApplicant" minOccurs="0" maxOccurs="1"/&gt;
        &lt;xs:element ref="Asset" minOccurs="0" maxOccurs="1"/&gt;
      &lt;/xs:any&gt;
  
      &lt;xs:any&gt;
        &lt;xs:element name="UserID" type="xs:string" minOccurs="1"/&gt;
        &lt;xs:element name="Password" type="xs:string" minOccurs="1"/&gt;
        &lt;xs:element name="ReferenceNumber" type="xs:string" minOccurs="0"  maxOccurs="1"/&gt;
        &lt;xs:element name="CustomerId" minOccurs="1" maxOccurs="1"&gt;
          &lt;xs:simpleType&gt;
            &lt;xs:restriction base="xs:integer"&gt;
              &lt;xs:minInclusive value="1"/&gt;
            &lt;/xs:restriction&gt;
          &lt;/xs:simpleType&gt;
        &lt;/xs:element&gt;
        &lt;xs:element ref="Asset" minOccurs="0" maxOccurs="1"/&gt;
      &lt;/xs:any&gt;
  
     &lt;/xs:choice&gt;
  &lt;/xs:complexType&gt;
  </code></pre>
  
  <p></p>
  
  <p>Any XSD experts (do these even exist?!) who are able to lend a hand or some advice?</p>