XmlReaderSettings::DtdProcessing Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets a value that determines the processing of DTDs.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

property DtdProcessing DtdProcessing {
	DtdProcessing get();
	void set(DtdProcessing value);

Property Value

Type: System.Xml::DtdProcessing

One of the enumeration values that determines the processing of DTDs. The default is Prohibit.

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.

This property can have one of the following values:

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.


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.

The following example validates an XML file using a DTD file.

#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;
using namespace System::IO;

// Display any validation errors.
static void ValidationCallBack( Object^ /*sender*/, ValidationEventArgs^ e )
   Console::WriteLine( L"Validation Error: {0}", e->Message );

int main()
   // Set the validation settings.
   XmlReaderSettings^ settings = gcnew XmlReaderSettings;
   settings->DtdProcessing = DtdProcessing::Parse;
   settings->ValidationType = ValidationType::DTD;
   settings->ValidationEventHandler += gcnew ValidationEventHandler( ValidationCallBack );

   // Create the XmlReader object.
   XmlReader^ reader = XmlReader::Create( L"itemDTD.xml", settings );

   // Parse the file. 
   while ( reader->Read() )

   return 1;

The example uses the itemDTD.xml file as input.

<!--XML file using a DTD-->
<!DOCTYPE store [
  <!ELEMENT store (item)*> 
  <!ELEMENT item (name,dept,price)>
  <!ELEMENT name (#PCDATA)>
  <!ELEMENT price (#PCDATA)>]>
  <item type="supplies"  ISBN="2-3631-4">

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top