title: XSD content model with a simpleType or a complexType child element?
body: <p>I'm trying to get an XML element be able to use a <code>complexType</code> and a <code>simpleType</code> for its type attribute. I'm relatively new to XML and XSD, and I'm not sure if this is possible. I wrote some test code to explain the problem.</p>
  
  <p>The one semi-sort of solution I've got to work was just creating two different <code>EntityType</code> types, but in this case, I do not want to do that because rewriting all the same elements into a new type just to change the <code>PhoneNumber</code> element type in the two <code>EntityType</code> types feels like a waste of code, especially when <code>EntityType</code> could have a lot more elements in it. I've tried looking into XML version 1.1 and using <code>xs:alternative</code>, but I'm not sure if it would work in this particular situation.</p>
  
  <p>Here is my XML: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;City&gt;
      &lt;Bob&gt;
          &lt;Name&gt;Bob&lt;/Name&gt;
          &lt;PhoneNumber&gt;262-662-6262&lt;/PhoneNumber&gt;
      &lt;/Bob&gt;
  
      &lt;QMart&gt;
          &lt;Name&gt;QMart&lt;/Name&gt;
          &lt;PhoneNumber&gt;
              &lt;FAX&gt;#45654&lt;/FAX&gt;
              &lt;PhoneNumber&gt;262-333-3939&lt;/PhoneNumber&gt;
              &lt;PhoneNumber2&gt;262-412-8633&lt;/PhoneNumber2&gt;
          &lt;/PhoneNumber&gt;
      &lt;/QMart&gt;
  &lt;/City&gt;
  </code></pre>
  
  <p>And here is the XSD:</p>
  
  <pre><code>?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
      &lt;xs:element name="City" type="CityType"/&gt;
  
      &lt;xs:complexType name="CityType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Bob" type="EntityType"/&gt;
              &lt;xs:element name="QMart" type="EntityType"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="EntityType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="Name" type="NameType"/&gt;
  
              &lt;!-- I want both Bob and QMart to use the same EntityType type,
                  but the only difference is that QMart uses the complex
                  PhoneNumberType for element PhoneNumber, while Bob uses
                  the simple PhoneNumberValueType for the PhoneNumber element
  
                  Bob: &lt;xs:element name="PhoneNumber" type="PhoneNumberValueType"/&gt; 
                  QMart: &lt;xs:element name="PhoneNumber" type="PhoneNumberType"/&gt;
              --&gt;
  
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:complexType name="PhoneNumberType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="FAX" type="FAXType"/&gt;
              &lt;xs:element name="PhoneNumber" type="PhoneNumberValueType"/&gt;
              &lt;xs:element name="PhoneNumber2" type="PhoneNumberValueType"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  
      &lt;xs:simpleType name="PhoneNumberValueType"&gt;
          &lt;xs:restriction base="xs:string"/&gt;
      &lt;/xs:simpleType&gt;
  
      &lt;xs:simpleType name="NameType"&gt;
          &lt;xs:restriction base="xs:string"/&gt;
      &lt;/xs:simpleType&gt;
  
      &lt;xs:simpleType name="FAXType"&gt;
          &lt;xs:restriction base="xs:string"/&gt;
      &lt;/xs:simpleType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>I've tried validating the XML and XSD with a <code>xs:union</code> element, but that only works for <code>simpleTypes</code> only. I'm not sure what else I can do and I'm running out of ideas. Any help is appreciated!</p>