xsd validation enum element required or optional (xs:schema version 1.0 )
<p>I have xsd validation file: </p>

<pre><code>&lt;xs:complexType name="metadata"&gt;
        &lt;xs:sequence&gt;
            &lt;xs:element name="app_name" type="AppDataType" minOccurs="4" maxOccurs="unbounded" /&gt;
        &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;

&lt;xs:complexType name="AppDataType"&gt;
        &lt;xs:attribute name="ERE" type="xs:string" use="required" /&gt;
        &lt;xs:attribute name="Name" type="AppDataName" use="required" /&gt;
        &lt;xs:attribute name="Value" type="xs:string" use="required" /&gt;
&lt;/xs:complexType&gt;

&lt;xs:simpleType name="AppDataName"&gt;
    &lt;xs:restriction base="xs:string"&gt;
        &lt;xs:enumeration value="enum_1" /&gt;
        &lt;xs:enumeration value="enum_2" /&gt;
        &lt;xs:enumeration value="enum_3" /&gt;
        &lt;xs:enumeration value="enum_4" /&gt;
    &lt;/xs:restriction&gt;
&lt;/xs:simpleType&gt;
</code></pre>

<p>Validation works fine when app_name appear in xml less than 4 times - its ok. 
Problem is, when app_name appear 4 or more time but with "Name" value setup to eg enum_1, enum_2, enum_2, enum_2, enum_4 -> I have at least 4 app_name so validation is passed (elements can be repeated - its ok for me), but I need to have also enum_3 in app_name, basically I want to have (eg) enum_3 and enum_1 as a required(if not appear in xml then validation fails), but enum_2 and enum_4 as optional.</p>

<p>I tried:</p>

<pre><code>&lt;xs:enumeration value="enum_2" use="required"/&gt;
</code></pre>

<p>but is incorrect as well as minOccurs="1".</p>

<p>I also tried: </p>

<pre><code>    &lt;xs:complexType name="metadata"&gt;
        &lt;xs:sequence&gt;
            &lt;xs:element name="app_name" type="AppDataType" minOccurs="4" maxOccurs="unbounded" /&gt;
            &lt;xs:element name="app_name" type="SOME_COMPLEX_TYPE_WITH_ENUM_1_AS_NAME" minOccurs="1" maxOccurs="unbounded" /&gt;     
        &lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
</code></pre>

<p>but in sequence there cannot appear two elements with same name (I cannot change this name).</p>

<p>So is there any way, to achive this in xs:schema version="1.0"</p>

<p>adding some example xml:</p>

<ol>
<li><p>validation passed: (OK)</p>

<pre><code>  &lt;Metadata&gt;
    &lt;app_name ERE="some_ere" Name="enum_1" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_2" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_3" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_4" Value="some_value"/&gt;
    &lt;/Metadata&gt;
</code></pre></li>
<li><p>validation passed: (OK)</p>

<pre><code>    &lt;Metadata&gt;
    &lt;app_name ERE="some_ere" Name="enum_1" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_1" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_3" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_4" Value="some_value"/&gt;
    &lt;/Metadata&gt;
</code></pre></li>
<li><p>validation passed: (OK) its ok, enum_1 and enum_3 (which for me are required) and at least 4 app_name -> validation pass </p>

<pre><code>    &lt;Metadata&gt;
    &lt;app_name ERE="some_ere" Name="enum_1" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_1" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_3" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_3" Value="some_value"/&gt;
    &lt;/Metadata&gt;
</code></pre></li>
<li><p>validation passed: (NOT OK - missing enum_1 which I want to be required, but right now validation is pass - xsd check only count of app_name occurs) </p>

<pre><code>  &lt;Metadata&gt;
    &lt;app_name ERE="some_ere" Name="enum_2" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_2" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_3" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_3" Value="some_value"/&gt;
    &lt;app_name ERE="some_ere" Name="enum_4" Value="some_value"/&gt;
    &lt;/Metadata&gt;
</code></pre></li>
</ol>

<p>Shortly (response to comment):</p>

<p>I want to have xsd validation which check if in xml document exists elements:</p>

<pre><code>&lt;metadata&gt;
&lt;ERE ..... name="enum_1".../&gt; 
&lt;ERE ..... name="enum_3".../&gt;
&lt;/metadata&gt;
</code></pre>

<p>if those element not exists, then validation should fail. </p>