title: How to write XSD for optional elements?
body: <p>Input:</p>
  
  <pre><code>&lt;params&gt;
     &lt;param name ="query" &gt;
      &lt;queryData&gt;
          &lt;criterialist  isCaseSensitive ="true"&gt;
              &lt;criteria&gt;
                  &lt;condition&gt;is&lt;/condition&gt;
                  &lt;value&gt;2&lt;/value&gt;
                  &lt;attributeName&gt;ActivityVersionId&lt;/attributeName&gt;
              &lt;/criteria&gt;
          &lt;/criterialist&gt;
         &lt;/queryData&gt;
     &lt;/param&gt;
  &lt;/params&gt;
  </code></pre>
  
  <p>In the above input the <code>criterialist</code> is optional. So I can have a input like the below as well.</p>
  
  <pre><code>&lt;params&gt;
    &lt;param name ="query" &gt;
      &lt;queryData&gt;
         &lt;/queryData&gt;
    &lt;/param&gt;
  &lt;/params&gt;
  </code></pre>
  
  <p>How can I validate these above input with a single XSD?</p>
  
  <p>The XSD which I am using now is:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified"&gt;
    &lt;xs:element name="params" type="paramsType"/&gt;
    &lt;xs:complexType name="criteriaType"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element type="xs:string" name="condition"/&gt;
        &lt;xs:element type="xs:byte" name="value"/&gt;
        &lt;xs:element type="xs:string" name="attributeName"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
    &lt;xs:complexType name="criterialistType"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element type="criteriaType" name="criteria"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute type="xs:string" name="isCaseSensitive"/&gt;
    &lt;/xs:complexType&gt;
    &lt;xs:complexType name="queryDataType"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element type="criterialistType" name="criterialist"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
    &lt;xs:complexType name="paramType"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element type="queryDataType" name="queryData"/&gt;
      &lt;/xs:sequence&gt;
      &lt;xs:attribute type="xs:string" name="name"/&gt;
    &lt;/xs:complexType&gt;
    &lt;xs:complexType name="paramsType"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element type="paramType" name="param"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>This validates the first input, but not the second one.</p>