Ignoring DTD with .NET XmlReader

I had an issue earlier today where I had an XML file that has a DTD declared and this is a security issue for the .NET XmlReader so I needed to find a way to ignore the DTD. Obviously I thought passing an XmlReaderSettings object to the XmlReader with ProhibitDtd set to false but this didn’t work. I knew it wouldn’t be THAT simple, and after a bit more searching I finally found the second key, you need to set the XmlResolver to null. Once you do that, you can parse XML using the XmlReader even if it has a DTD declared.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s