title: validate xml file using xsd in C#.. How much does it actually validate?
body: <p>Have have been trying to make a validator for my xml files. I have used some of the other examples that can be found on this site (like <a href="https://stackoverflow.com/questions/3465335/how-to-validate-an-xml-document">How to validate an XML document?</a>). </p>
  
  <p>I just don't see it working the way I expect. What does actually get validated?</p>
  
  <p>Almost no matter what I change in the xml file, the validator dosent sees it as an error. I thought the validator would see if the xml file contains an element not defined in the xsd. The validator only catches normal xml syntax  errors. </p>
  
  <p>So whats the point of using the xsd if it doesn't have an influence?</p>
  
  <p><strong>My validator</strong></p>
  
  <pre><code>string xsd_file = "Message.xsd";
  XmlSchema xsd = new XmlSchema();
  xsd.SourceUri = xsd_file;
  
  XmlSchemaSet ss = new XmlSchemaSet();
  ss.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);
  ss.Add(null, xsd_file);
  if (ss.Count &gt; 0)
  {
      XmlReaderSettings settings = new XmlReaderSettings();
      settings.ValidationType = ValidationType.Schema;
      settings.Schemas.Add(ss);
      settings.Schemas.Compile();
      settings.ValidationEventHandler += new ValidationEventHandler(ValidationEventHandler);
      XmlTextReader r = new XmlTextReader(filepath);
      using (XmlReader reader = XmlReader.Create(r, settings))
      {
          try
          {
              while (reader.Read())
              {
              }
          }
          catch (XmlException ex)
          {
  
              throw;
          }                        
      }
  }
  </code></pre>