title: Reading and writing to an XML - DTD error
body: <p>I have a program where it reads and writes XML using XMLReader and XMLWriter</p>
  
  <pre><code> XmlWriter writer =
   XmlWriter.Create(fullpath, settings);
  
   //content...
  
   writer.Flush();
  
   writer.Close();
  </code></pre>
  
  <p>and my reader code</p>
  
  <pre><code>XmlReader reader = XmlReader.Create(fullpath);
  
  while (reader.Read())
          {
              switch(reader.NodeType)
              {
                  case XmlNodeType.Element:
                      Console.WriteLine("Element: " + reader.Name);
  
                      while(reader.MoveToNextAttribute())
                      {
  
                          Console.WriteLine("\tAttribute: [" + reader.Name + "] = '" + 
                          reader.Value + "'");
                      }
                      break;
  
                  case XmlNodeType.DocumentType: 
                      Console.WriteLine("Document: " + reader.Value); 
                      break;
  
                  case XmlNodeType.Comment:
                      Console.WriteLine("comment: " + reader.Value);
                      break;
  
                  default: 
                      Console.WriteLine("unknown type, error!");
                      break;
              }
          }
  
          reader.Close()
  </code></pre>
  
  <p>The writer works fine, but when it gets to XmlReader reader = XmlReader.Create(fullpath);</p>
  
  <p>it prints the unknown type error message twice and crashes with the error</p>
  
  <blockquote>
    <p>Unhandled Exception:
    System.Xml.XmlException: For security
    reasons DTD is prohib
        ited in this XML document. To enable DTD processing set the
    ProhibitDtd property
         on XmlReaderSettings to false and pass the settings into
    XmlReader.Create metho
        d.
           at System.Xml.XmlTextReaderImpl.Throw(Exception
    e)
           at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String
    res, String arg)
           at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
           at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
           at System.Xml.XmlTextReaderImpl.Read()
           at writefile.Main() in C:\Main\C#June\CH9\CodeFile1.cs:line</p>
  </blockquote>
  
  <p>I tried adding this before XmlReader.Create(fullpath)</p>
  
  <pre><code>XmlReaderSettings settingsread = new XmlReaderSettings();
  settingsread.ProhibitDtd = false;
  </code></pre>
  
  <p>I still get the same error, what's the real problem in this program?</p>