I am trying to load xml content using XmlTextReader but for some reason, XmlTextReader is ignoring DtdProcessing flag while processing Xml. DtdProcessing flag is working fine if I use XmlReader instead. Problem with XmlReader is that it automatically normalize \r\n\ to \n which I don't want in my output string.
Here is my code snippet:
XmlDocument xmlDocument = new XmlDocument();
string contents = @"<?xml version='1.0' encoding='ISO-8859-1' standalone='yes'?>
<!DOCTYPE content [<!ENTITY ouml 'ö'>]>
<content>Test ö Test
Test</content>";
byte[] byteArray = Encoding.UTF8.GetBytes(contents);
MemoryStream stream = new MemoryStream(byteArray);
//XmlReaderSettings settings = new XmlReaderSettings();
//settings.DtdProcessing = DtdProcessing.Parse;
//settings.IgnoreWhitespace = false;
//XmlReader reader = XmlReader.Create(stream, settings);
//xmlDocument.Load(reader);
XmlTextReader reader = new XmlTextReader(stream);
reader.DtdProcessing = DtdProcessing.Parse;
xmlDocument.Load(reader);
Console.WriteLine(xmlDocument.OuterXml);
Output I am getting from above processing:
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?><!DOCTYPE content[<!ENTITY ouml 'ö'>]><content>Test ö Test\r\n\r\n Test</content>"
Instead I want output string with the DTD processed:
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?><!DOCTYPE content[<!ENTITY ouml 'ö'>]><content>Test ö Test\r\n\r\n Test</content>"