title: xsd same element, different types?
body: <p>I have a situation where an element in the XML-file can be of two different types in the XSD.</p>
  
  <p>What I want to do is first to validate the entered value to the more strict type (if it's a person that fills out the form) and if that doesn't pull through, validate it to the lesser strict type (if it's an organization that fills out the form), otherwise let the validation fail if it doesn't validate at all.</p>
  
  <p>So this is basically it:</p>
  
  <pre><code>&lt;xsd:complexType name="ForminfoType"&gt; `
      &lt;xsd:sequence&gt;
          &lt;xsd:element name="formname" type="xsd:string" /&gt;
          &lt;xsd:element name="timestamp" type="xsd:dateTime" /&gt;
          &lt;xsd:element name="sender" type="PersonType" minOccurs="0" /&gt;
          &lt;xsd:element name="receiver" type="OrganizationType" minOccurs="0" /&gt;
          &lt;xsd:element name="signature" type="xsd:string" minOccurs="0" /&gt;
      &lt;/xsd:sequence&gt;
  &lt;/xsd:complexType&gt; 
  </code></pre>
  
  <p>What the PersonType declares is basically a 12-digit number constructed according to a specific pattern. What the Organization type declares is basically just a 10-digit number. </p>
  
  <p>So what I logically would like to do is to put this:</p>
  
  <pre><code>&lt;xsd:element name="sender" type="OrganizationType" minOccurs="0" /&gt;
  </code></pre>
  
  <p>into the sequence, but you can't have two elements with the same name and different types. So I reckon I must solve it in some other way. </p>
  
  <p>What I have found was this:
  <a href="http://xsd.stylusstudio.com/2007Oct/post05003.htm" rel="noreferrer">http://xsd.stylusstudio.com/2007Oct/post05003.htm</a></p>
  
  <p>Which is pretty much what I want to do, but I'm not sure it's possible. 
  Has anyone got any further ideas on how to solve this?</p>
  
  <p>Thanks in advance.</p>