title: Read typed objects from XML using known XSD
body: <p>I have the following (as an example) XML file and XSD.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;foo&gt;
    &lt;DateVal&gt;2010-02-18T01:02:03&lt;/DateVal&gt;
    &lt;TimeVal&gt;PT10H5M3S&lt;/TimeVal&gt;
  &lt;/foo&gt;
  </code></pre>
  
  <p>and </p>
  
  <p>
  
  <pre><code>version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:element name="foo"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="DateVal" type="xs:dateTime" /&gt;
          &lt;xs:element name="TimeVal" type="xs:duration" /&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <hr>
  
  <p>Then the following C# code:</p>
  
  <pre><code>  static void Main(string[] args)
    {
       XmlDocument xd = new XmlDocument();
       XmlSchema xs;
       using (var fs = File.OpenRead(FilePath + "SimpleFields.xsd"))
       {
          xs = XmlSchema.Read(fs, null);
       }
  
       xd.Schemas.Add(xs);
       xd.Load((FilePath + "SimpleFields.xml"));
       xd.Validate(null);
  
       var el_root = xd.DocumentElement;
  
       var el_date = (XmlElement)el_root.SelectSingleNode("./DateVal");
       //WANTED: el_date.Value = 2010-02-18 01:02:03 (as a DateTime Object)
       //ACTUAL: el_date.InnerText="2010-02-18T01:02:03"
  
       var el_duration = (XmlElement)el_root.SelectSingleNode("./TimeVal");
       //WANTED: el_date.Value = 10 hours, 5 minutes, 3 seconds (as a TimeSpan Object)
       //ACTUAL: el_date.InnerText="PT10H5M3S"
  
       Console.WriteLine("DONE");
       Console.ReadLine();
    }
  </code></pre>
  
  <hr>
  
  <p>How can I read the data as strongly typed objects ? </p>
  
  <p>I will be targetting a WindowsMobile device, but this shouldn't need to affect the answer too much. (can be .NET 2.0 or 3.5 ... Not sure if Sstem.Xml.Linq will help or not)</p>