Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 903981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:58:36+00:00 2026-05-15T15:58:36+00:00

I have a program where it reads and writes XML using XMLReader and XMLWriter

  • 0

I have a program where it reads and writes XML using XMLReader and XMLWriter

 XmlWriter writer =
 XmlWriter.Create(fullpath, settings);

 //content...

 writer.Flush();

 writer.Close();

and my reader 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()

The writer works fine, but when it gets to XmlReader reader = XmlReader.Create(fullpath);

it prints the unknown type error message twice and crashes with the error

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

I tried adding this before XmlReader.Create(fullpath)

XmlReaderSettings settingsread = new XmlReaderSettings();
settingsread.ProhibitDtd = false;

I still get the same error, what’s the real problem in this program?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:58:37+00:00Added an answer on May 15, 2026 at 3:58 pm

    I believe you would need to change your reader create to reference the settings

    XmlReader reader = XmlReader.Create(fullpath);
    

    should become

    XmlReader reader = XmlReader.Create(fullpath, settingsread);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which reads an XML file using the DOM functions: $doc
I have a program that reads from a file that grabs 4 bytes from
I have a program that reads data from a file line-by-line. I would like
I have a program that reads input from a file. I am trying to
I have a program which reads Inbox messages from email accounts, as the title
I have a program that reads a file, treat it and put the results
I have a program that reads one image file, makes some changes on that
Currently, I have a program that reads a file and uses an XMLTextWriter to
i want to develop a pretty basic client-server program. one software reads xml (or
We have a Perl program to validate XML which is invoked from a Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.