title: Id and idref attributes in XSD
body: <p>I'm working on an assignment of putting together XML documentation for an event calendar, which consists of event elements that have child elements of name, date, venue, etc. Several events have the same venue but the contact info for each venue is listed only once in the XML data. So, what I have in the XML document:</p>
  
  <pre><code>&lt;venueinfo&gt;
      &lt;venue id="p1"&gt;
          &lt;name&gt;...&lt;/name&gt;
          &lt;address&gt;...&lt;/address&gt;
          ...
      &lt;/venue&gt;
      &lt;venue id="p2"&gt;
          ...
      &lt;/venue&gt;
      ...
  &lt;/venueinfo&gt;
  </code></pre>
  
  <p>And in the event elements:</p>
  
  <pre><code>&lt;event&gt;
      &lt;name&gt;...&lt;/name&gt;
      ...
      &lt;location idref="p1"/&gt;
      ...
  &lt;/event&gt;
  </code></pre>
  
  <p>In XSD I need to link the  elements of  elements to the corresponding  elements in , but so far I haven't got the linking correctly. Here are the pertinent attribute and element declarations:</p>
  
  <pre><code>&lt;-- root element --&gt;
  &lt;xs:element name="eventcalendar"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="tapahtuma" maxOccurs="unbounded"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;xs:attribute name="id" type="xs:ID"/&gt;
  &lt;xs:attribute name="idref" type="xs:IDREF"/&gt;
  
  &lt;xs:element name="venueinfo"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="venue" maxOccurs="unbounded"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;xs:element name="venue"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="name"/&gt;
              &lt;xs:element ref="address"/&gt;
              ...
          &lt;/xs:sequence&gt;
          &lt;xs:attribute ref="id" use="required"/&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;xs:element name="location"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:simpleContent&gt;
              &lt;xs:extension base="xs:string"&gt;
                  &lt;xs:attribute ref="idref" use="required"/&gt;
              &lt;/xs:extension&gt;
          &lt;/xs:simpleContent&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;xs:element name="event"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element ref="category"/&gt;
              ...
              &lt;xs:element ref="location"/&gt;
              ...
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>Validation of the XML gives me "element 'venueinfo' is not allowed for content model '(event+)'". Could someone advice me as to what I should do to get this correctly? Many thanks.</p>