title: C# Get schema information when validating xml
body: <p>I'm trying to validate some XML against a schema and gather as much information as possible to provide valuable error messages to the user.</p>
  
  <p>I've managed to validate a serialized object against an XSD. My ValidationEventHandler is being called properly for all errors and I get get some information there. The only problem is that schema information is not available at this point - I'm trying to get to the schema type of the element. i.e. given the following schema element, I would like to get "BookType"</p>
  
  <pre><code>&lt;element minOccurs="0" maxOccurs="1" name="TypeOfBook" type="myTypes:BookType" /&gt;
  </code></pre>
  
  <p>I believe schema/validation information is being inserted into the xml during the validation process. So if I call validate twice in a row, only handling the erros the second time around, the schema information is available.</p>
  
  <pre><code>serializedObject.Validate((x, y) =&gt; { });
  serializedObject.Validate((x, y) =&gt; { // handle errors here because elements will have schema info available });
  </code></pre>
  
  <p>Obviously, this solution leaves much to be desired. What is the recommended way of dealing with this?</p>