Reading XML files that have a full DTD

Trying to read data out of an xml file. I've gotten several simple examples to work, but as soon as I add DTD information I get this error 'XmlException: Document Type Declaration (DTD) is prohibited in this XML...' Is there and error in my DTD? I have a hard time imagining that an XML parser breaking on DTD would be widely used, but this error looks like it simply fails on files with a DTD in them.

Normally I'd simply comment out the DTD so that it would work until I found a solution, but this database actually relies on the entity information included in the DTD to function.

As always, any assistance in this matter is greatly appreciated.

It’s been awhile but I’ll post a possible solution anyway.

A similar error occurs with C# when using Linq to XML (in my case on Linux using mono 2.6.7) if you try to directly open an XML file with the XDocument object and the XML document contains an embedded DTD. For example:

XDocument xml = Xdocument.Load("data.xml");

will throw the error.

A way around that is to pass an XmlReader to the XDocument load method that has it’s “ProhibitDtd” property set to false. For example:

XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
			
XmlReader reader = XmlReader.Create("data.xml", settings);
			
XDocument xml = XDocument.Load(reader);

Hope this helps somebody.