title: Unexpected exception while validating XML code
body: <p>In .NET/C#, I want to validate some html code. For instance I have the following HTML :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
    &lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt;
    &lt;body&gt;
     CDATA section number 1?
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I have the following C# code:</p>
  
  <pre><code>string htmlCode = ... // for instance the html above
  var settings = new XmlReaderSettings { ValidationType = ValidationType.DTD };
  settings.ValidationEventHandler += delegate(object s, ValidationEventArgs e)
  {
      throw new XmlException(e.Message);
  };
  using (var srdr = new StringReader(htmlCode))
  using (var xrdr = new XmlTextReader(srdr))
  using (var vrdr = XmlReader.Create(xrdr, settings))
  {
      try
      {
          while (vrdr.Read()) { }
      }
      catch (XmlException ex)
      {
          // do some stuff
      }
  }
  </code></pre>
  
  <p>when I run this code I have this exception:  </p>
  
  <blockquote>
    <p>System.Net.WebException : The remote server returned an error: (403) Forbidden.<br>
    at System.Net.HttpWebRequest.GetResponse()</p>
  </blockquote>
  
  <p>What's wrong in what I've done? Thanks in advance for your help </p>