System.Xml.XmlReaderSettings.DtdProcessing property
This article provides supplementary remarks to the reference documentation for this API.
Document type definition (DTD) validation is implemented by using the validity constraints defined in the W3C Extensible Markup Language (XML) 1.0 (fourth edition) recommendation. DTDs use a formal grammar to describe the structure and syntax of compliant XML documents; they specify the content and values allowed for the XML document.
The DtdProcessing property can have one of the following values:
- DtdProcessing.Parse to enable DTD processing.
- DtdProcessing.Prohibit to throw an XmlException exception when a DTD is encountered.
- DtdProcessing.Ignore to disable DTD processing without warnings or exceptions.
To perform validation against a DTD, the XmlReader uses the DTD defined in the DOCTYPE declaration of an XML document. The DOCTYPE declaration can either point to an inline DTD or can be a reference to an external DTD file. To validate an XML file against a DTD:
- Set the XmlReaderSettings.DtdProcessing property to
DtdProcessing.Parse
. - Set the XmlReaderSettings.ValidationType property to
ValidationType.DTD
. - If the DTD is an external file stored on a network resource that requires authentication, pass an XmlResolver object with the necessary credentials to the Create method.
Important
If the DtdProcessing property is set to DtdProcessing.Ignore, the XmlReader will not report the DTDs. This means that the DTD/DOCTYPE will be lost on output.