title: Having both an attribute and a restriction on an element in xml schema
body: <p>I'm trying to write a xml schema that will validate this piece of xml:</p>
  
  <pre><code>&lt;date isodate="2007-03-14"&gt;14 march 2007&lt;/date&gt;
  </code></pre>
  
  <p>The attribute isodate should have it's type set to xs:date and the content should be max 50 characters long.</p>
  
  <p>I wonder if it's possible to write the xml schema definition in one block, something like this maybe:</p>
  
  <pre><code>&lt;xs:element name="date" minOccurs="0" maxOccurs="1"&gt;  
    &lt;xs:complexType&gt;  
      &lt;xs:simpleContent&gt;  
        &lt;xs:restriction base="xs:string"&gt;  
          &lt;xs:minLength value="0"/&gt;  
          &lt;xs:maxLength value="50"/&gt;  
        &lt;/xs:restriction&gt;  
        &lt;xs:attribute name="isodate" type="xs:date" use="required"/&gt;  
      &lt;/xs:simpleContent&gt;  
    &lt;/xs:complexType&gt;  
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>The code above doesn't work, and I can't really figure out why. Only workaround I have found is to break out the restriction part into a separate type, and link that like this:</p>
  
  <pre><code>&lt;xs:simpleType name="reviewDate"&gt;  
      &lt;xs:restriction base="xs:string"&gt;  
          &lt;xs:minLength value="0"/&gt;  
          &lt;xs:maxLength value="50"/&gt;  
      &lt;/xs:restriction&gt;  
  &lt;/xs:simpleType&gt;
  
  &lt;xs:element name="date" minOccurs="0" maxOccurs="1"&gt;  
      &lt;xs:complexType&gt;  
          &lt;xs:simpleContent&gt;  
              &lt;xs:extension base="reviewDate"&gt;  
                  &lt;xs:attribute name="isodate" type="xs:date" use="required"/&gt;  
              &lt;/xs:extension&gt;  
          &lt;/xs:simpleContent&gt;  
      &lt;/xs:complexType&gt;  
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>The question I have is how to write the definition in one block so that the schema is a bit more readable, and doesn't reference types in other parts of the schema.</p>