title: XML Parsing using a schema in C#
body: <p>I'm working on some code that loads an xml file at run time. At the minute, we're using the XmlDocument type to read the xml file and wrapping a try-catch around SelectSingleNode statement (this is done on the off chance that a node is null, or isn't there as we're parsing user created xml files).</p>
  
  <p><strong>Please note</strong>: I realise that XmlDocument has been replaced by XDocument. However since we're working with  .NET version 3 (<a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx" rel="nofollow">according to this MSDN document</a> XDocument isn't available in .NET 3), we're having to stick with XmlDocument for now. We're using .NET 3 for a variety of reasons (some of which are spec related).</p>
  
  <p>Here's an example of what we're doing at the minute:</p>
  
  <pre><code>private void LoadUserXMLFile ()
  {
      XmlDocument xDoc = new XmlDocument();
      XmlTextReader reader = new XmlTextReader(fileName);
      reader.Read();
      xDoc.Load(reader);
  
      try { firstElementString = xDoc.SelectSingleNode(&lt;path to node&gt;).InnderText);
      catch { &lt;exception handling here &gt; }
      //more SelectSingleNode statements, each wrapped inside
      //individual try-catch blocks
  }
  </code></pre>
  
  <p>Obviously the above is an example, and I've simplified the catch statement.</p>
  
  <p>I've written a schema for the user generated XML files that this app will work with, and I was wondering if I used the schema (in some way) during parsing of an XML document, would I still need to wrap each SelectSingleNode with try-catch statements?</p>
  
  <p>Is it even possible to use the schema (in some way) during parsing to check the XML document has the correct format and all of the required elements?</p>