title: XML Validation error: The element is not declared
body: <p>I am building a web service in .NET that will pass data back and forth via XML. I would like to validate the XML in the incoming requests using an XSD that I have defined. </p>
  
  <p>Here is the XSD:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
     &lt;xs:complexType name="POSearch"&gt;
         &lt;xs:sequence minOccurs="0" maxOccurs="10"&gt;
             &lt;xs:element name="POID" type="xs:positiveInteger"/&gt;
         &lt;/xs:sequence&gt;
     &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Here is the XML:</p>
  
  <pre><code>&lt;POSearch&gt;
     &lt;POID&gt;1&lt;/POID&gt;
     &lt;POID&gt;2&lt;/POID&gt;
  &lt;/POSearch&gt;
  </code></pre>
  
  <p>Here is the validation code in C#:</p>
  
  <pre><code>static void Main(string[] args){
     XmlSchemaSet iSchemas = new XmlSchemaSet();
     iSchemas.Add(string.Empty, @"...xsd file location");
  
     XmlReaderSettings settings = new XmlReaderSettings();
     settings.ValidationType = ValidationType.Schema;
     settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
     settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
     settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
     settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
     settings.Schemas.Add(iSchemas);
  
     XmlReader reader = XmlReader.Create(@"...xml file location", settings);
  
     try {
        while(reader.Read())
         ;
     }
     catch(Exception ex) {
        Console.WriteLine(ex.Message);
     }
  }
  
  private static void ValidationCallBack(object sender, ValidationEventArgs args) {
       if(args.Severity == XmlSeverityType.Warning)
          Console.WriteLine("\tWarning: Matching schema not found.  No validation occurred." + args.Message);
       else
          Console.WriteLine("\tValidation error: " + args.Message);
    }
  </code></pre>
  
  <p>I feel like I had this working before and I'm not completely sure why this isn't working now. Whenever I run this I get the following Exception Message:</p>
  
  <blockquote>
    <p>Validation error: The 'POSearch' element is not declared.</p>
  </blockquote>
  
  <p>Have I defined my XSD wrong? Is my validation code wrong? The elements are all clearly there. Any help pointing me in the right direction is greatly appreciated.</p>