title: XML schema xs:choice inside xs:sequence
body: <p>I'm trying to use a xs:choice element, but while validating the XSD file, I'm getting an error which I suppose it's related to the xs:choice element. I've searched for this problem for quite a bit, found some similar ones, but none gave me the answer I was looking for in order to solve my problem.</p>
  
  <p>What I'm trying to do is, declare an element called "data", whose childs would be a timestamp and a sensor or a provider (here is where I'm trying to use a choice element, since I only want a sensor or provider element as sibling of the timestamp).</p>
  
  <p>The following XML is what I'm trying to validate:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;experience xmlns="http://www.w3schools.com"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" &gt;
  &lt;data&gt;
      &lt;timestamp&gt;123456789&lt;/timestamp&gt;
      &lt;sensor origin="proximity" &gt;
          &lt;x-axis&gt;9&lt;/x-axis&gt;
          &lt;y-axis&gt;0&lt;/y-axis&gt;
          &lt;z-axis&gt;0&lt;/z-axis&gt;
          &lt;w-axis&gt;0&lt;/w-axis&gt;
      &lt;/sensor&gt;
  &lt;/data&gt;
  &lt;/experience&gt;
  </code></pre>
  
  <p>And in order to validate this XML, I wrote the following XSD file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
  &lt;!-- definition of attributes --&gt;
  &lt;xs:attribute name="origin" type="xs:string" /&gt;
  
  &lt;!-- definition of complex elements --&gt;
      &lt;xs:element name="provider"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:all&gt;
                  &lt;xs:element name="latitude"  type="xs:float" /&gt;
                  &lt;xs:element name="longitude" type="xs:float" /&gt;
                  &lt;xs:element name="altitude"  type="xs:float" /&gt;
                  &lt;xs:element name="bearing"   type="xs:float" /&gt;
                  &lt;xs:element name="speed"     type="xs:float" /&gt;
              &lt;/xs:all&gt;
              &lt;xs:attribute ref="origin" use="required"/&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
      &lt;xs:element name="sensor"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:all&gt;
                  &lt;xs:element name="x-axis" type="xs:float" /&gt;
                  &lt;xs:element name="y-axis" type="xs:float" /&gt;
                  &lt;xs:element name="z-axis" type="xs:float" /&gt;
                  &lt;xs:element name="w-axis" type="xs:float" /&gt;
              &lt;/xs:all&gt;
              &lt;xs:attribute ref="origin" use="required"/&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
      &lt;xs:element name="data"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="timestamp" minOccurs="1" maxOccurs="1" /&gt;
  
                  &lt;xs:choice&gt;
                      &lt;element ref="provider" /&gt;
                      &lt;element ref="sensor" /&gt;
                  &lt;/xs:choice&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  
  &lt;!-- definition of main type --&gt;
      &lt;xs:element name="experience"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="data" minOccurs="0" maxOccurs="unbounded"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>But once I upload the file and try to validate it using the <a href="http://www.w3.org/2001/03/webdata/xsv#" rel="nofollow">following w3 website</a>, I get the following error:</p>
  
  <blockquote>
    <p>file:/usr/local/XSV/xsvlog/tmph7cMmLuploaded:45:6: Invalid per
    cvc-complex-type.1.2.4: element {None}:element not allowed here (1) in
    element {<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema</a>}:choice, expecting
    [{<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema</a>}:annotation,$,{<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema</a>}:element,{<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema</a>}:group,{<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema</a>}:choice,{<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema</a>}:sequence,{<a href="http://www.w3.org/2001/XMLSchema" rel="nofollow">http://www.w3.org/2001/XMLSchema</a>}:any]:</p>
  </blockquote>
  
  <p>I think that the problem is in the xs:choice element, but I could be wrong.</p>
  
  <p>Since it's the first time I'm trying to use the xs:choice element, I have some doubts whether I'm using it correctly or not. According to the example in w3schools I am, but since I intend to use it next to another element, I don't know if it's correct anymore.</p>
  
  <p>If someone could help me on this one I would be very appreciated.</p>
  
  <p>Many thanks in advance.</p>