title: What's the difference between ref and type in an XML schema?
body: <p>Consider the following schema:</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;xs:complexType name="Root"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="Child" /&gt;
              &lt;xs:element name="Child2" type="Child" /&gt;
          &lt;/xs:sequence&gt;
          &lt;xs:attribute ref="Att" /&gt;
          &lt;xs:attribute name="Att2" type="Att" /&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="Child"&gt;
          &lt;xs:attribute ref="Att" /&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:attribute name="Att" type="xs:integer" /&gt;
  
  &lt;/xs:schema&gt; 
  </code></pre>
  
  <p>The <code>ref</code> to "Child" on line 6 fails, while the <code>type</code> on line 7 validates. For the attribute, the <code>ref</code> succeeds while the <code>type</code> fails. I'm trying to understand why.</p>
  
  <p>My understanding of <code>ref</code> was that it simply referred to another element and specified that you expect to see an instance of the referred type (with the name given in the definition) at that location. Obviously I'm wrong, so what does <code>ref</code> actually mean?</p>