title: Constraining localized enum values by xsd
body: <p>What I'm trying to achieve is build an xml structure that will be further used to generate event classes. These events that will be further used for user facing logs.
  These events may be simple messages or may contain parameters which can either be base types or enums, under the condition that the any enum type must be local to the event class that uses it.</p>
  
  <p>Let's take the example of an event that reports the temperature of something. It would look somewhat like this:</p>
  
  <pre><code>&lt;SoftwareEvent
  EventID="126.042.027"
  NiceID="InstrumentControl.TemperatureEvent"
  Message="The temperature of the cooling element is {0} of {1}-{2}°C."&gt;
  &lt;enumType name="ElementTemperatureStatus" base="int"&gt;
    &lt;enumValue value="InRange" EnglishMessage="within the acceptable range" /&gt;
    &lt;enumValue value="OutOfRange" EnglishMessage="outside the acceptable range" /&gt;
    &lt;enumValue value="AtLowerRangeLimit" EnglishMessage="near the lower limit of the acceptable range" /&gt;
    &lt;enumValue value="AtUpperRangeLimit" EnglishMessage="near the upper limit of the acceptable range" /&gt;
  &lt;/enumType&gt;
  &lt;Parameters&gt;
     &lt;Parameter name="temperatureStatus" type="enumeration" enumerationType="ElementTemperatureStatus"/&gt;
    &lt;Partameter name="rangeLowerLimit" type="double"/&gt;
    &lt;Partameter name="rangeUpperLimit" type="double"/&gt;
  &lt;/Parameters&gt;
  </code></pre>
  
  <p></p>
  
  <p>and this xml could be used to generate the event class and related localizable resources.
  I also want to use a schema(attached bellow) to enforce this structure and I've been mostly successful however I do have a problem that I can't quite fix.</p>
  
  <p>I would like to know if it's possible to use the xsd schema of such an xml to enforce the enumerationType type of the first event to be one of the enumTypes declared above in the scope of the same SoftwareEvent. And if so, how would one go about doing this?</p>
  
  <p>Here is the xsd I have a this point</p>
  
  <pre><code>&lt;xs:element name="SoftwareEvents"&gt;
  &lt;xs:complexType&gt;
    &lt;xs:sequence&gt;
      &lt;xs:element maxOccurs="unbounded" name="SoftwareEvent" &gt;
        &lt;xs:complexType mixed="true"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element name="enumType" minOccurs="0" maxOccurs="unbounded"&gt;
              &lt;xs:complexType&gt;
                &lt;xs:sequence&gt;
                  &lt;xs:element name="enumValue" minOccurs="0" maxOccurs="unbounded"&gt;
                    &lt;xs:complexType&gt;
                      &lt;xs:attribute name="value" use="required"&gt;
                        &lt;xs:simpleType&gt;
                          &lt;xs:restriction base="xs:string"&gt;
                            &lt;xs:pattern value="[a-zA-Z_][a-zA-Z0-9_]*"/&gt;
                          &lt;/xs:restriction&gt;
                        &lt;/xs:simpleType&gt;
                      &lt;/xs:attribute&gt;
                      &lt;xs:attribute name="EnglishMessage" use="required"&gt;
                        &lt;xs:simpleType&gt;
                          &lt;xs:restriction base="xs:string"/&gt;
                        &lt;/xs:simpleType&gt;
                      &lt;/xs:attribute&gt;
                    &lt;/xs:complexType&gt;
                  &lt;/xs:element&gt;
                &lt;/xs:sequence&gt;
                &lt;xs:attribute name="name" use="required"&gt;
                  &lt;xs:simpleType&gt;
                    &lt;xs:restriction base="xs:string"&gt;
                      &lt;xs:pattern value="[a-zA-Z_][a-zA-Z0-9_]*"/&gt;
                    &lt;/xs:restriction&gt;
                  &lt;/xs:simpleType&gt;
                &lt;/xs:attribute&gt;
                &lt;xs:attribute name="base" use="required"&gt;
                  &lt;xs:simpleType&gt;
                    &lt;xs:restriction base="xs:string"&gt;
                        &lt;xs:enumeration value="int"/&gt;
                        &lt;xs:enumeration value="byte"/&gt;
                        &lt;xs:enumeration value="long"/&gt;
                    &lt;/xs:restriction&gt;
                  &lt;/xs:simpleType&gt;
                &lt;/xs:attribute&gt;
              &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
            &lt;xs:element name="Parameters" minOccurs="0" maxOccurs="1"&gt;
              &lt;xs:complexType&gt;
                &lt;xs:sequence&gt;
                  &lt;xs:element name="Partameter" minOccurs="0" maxOccurs="unbounded"&gt;
                    &lt;xs:complexType&gt;
                      &lt;xs:attribute name="name" use="required"&gt;
                        &lt;xs:simpleType&gt;
                          &lt;xs:restriction base="xs:string"&gt;
                            &lt;xs:pattern value="[a-zA-Z_][a-zA-Z0-9_]*"/&gt;
                          &lt;/xs:restriction&gt;
                        &lt;/xs:simpleType&gt;
                      &lt;/xs:attribute&gt;
                      &lt;xs:attribute name="type" use="required"&gt;
                        &lt;xs:simpleType&gt;
                          &lt;xs:restriction base="xs:string"&gt;
                            &lt;xs:enumeration value="int"/&gt;
                            &lt;xs:enumeration value="double"/&gt;
                            &lt;xs:enumeration value="string"/&gt;
                            &lt;xs:enumeration value="long"/&gt;
                            &lt;xs:enumeration value="enumeration"/&gt;
                          &lt;/xs:restriction&gt;
                        &lt;/xs:simpleType&gt;
                      &lt;/xs:attribute&gt;
                      &lt;xs:attribute name="enumerationType" use="optional"&gt;
                        &lt;xs:simpleType&gt;
                          &lt;xs:restriction base="xs:string"&gt;
                            &lt;xs:pattern value="[a-zA-Z_][a-zA-Z0-9_]*"/&gt;
                          &lt;/xs:restriction&gt;
                        &lt;/xs:simpleType&gt;
                      &lt;/xs:attribute&gt;
                    &lt;/xs:complexType&gt;
                  &lt;/xs:element&gt;
                &lt;/xs:sequence&gt;
              &lt;/xs:complexType&gt;
            &lt;/xs:element&gt;
          &lt;/xs:sequence&gt;
          &lt;xs:attribute name="EventID" use="required" &gt;
            &lt;xs:simpleType&gt;
              &lt;xs:restriction base="xs:string"&gt;
                &lt;xs:pattern value="[\d]{3}.[\d]{3}.[\d]{3}"/&gt;
              &lt;/xs:restriction&gt;
            &lt;/xs:simpleType&gt;
          &lt;/xs:attribute&gt;
          &lt;xs:attribute name="NiceID" type="xs:string" use="required"  /&gt;
          &lt;xs:attribute name="Message" type="xs:string" use="required" /&gt;
        &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
    &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>