Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Propiedad XmlReaderSettings.DtdProcessing

 

Publicado: octubre de 2016

Obtiene o establece un valor que determine el procesamiento de DTD.

Espacio de nombres:   System.Xml
Ensamblado:  System.Xml (en System.Xml.dll)

public DtdProcessing DtdProcessing { get; set; }

Valor de propiedad

Type: System.Xml.DtdProcessing

Uno de los valores de enumeración que determina el procesamiento de DTD. De manera predeterminada, es 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) recommendationhttp://www.w3.org/TR/2006/REC-xml-20060816/. 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 T:System.Xml.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 P:System.Xml.XmlReaderSettings.DtdProcessing property to DtdProcessing.Parse.

  • Set the P:System.Xml.XmlReaderSettings.ValidationType property to ValidationType.DTD.

  • If the DTD is an external file stored on a network resource that requires authentication, pass an T:System.Xml.XmlResolver object with the necessary credentials to the Overload:System.Xml.XmlReader.Create method.

System_CAPS_importantImportante

If the P:System.Xml.XmlReaderSettings.DtdProcessing property is set to F:System.Xml.DtdProcessing.Ignore, the T:System.Xml.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;
using System.Xml;
using System.Xml.Schema;
using System.IO;

public class Sample {

  public static void Main() {

    // Set the validation settings.
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.DtdProcessing = DtdProcessing.Parse;
    settings.ValidationType = ValidationType.DTD;
    settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);

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


    // Parse the file. 
    while (reader.Read());

  }

  // Display any validation errors.
  private static void ValidationCallBack(object sender, ValidationEventArgs e) {
    Console.WriteLine("Validation Error: {0}", e.Message);
  }
}

The example uses the itemDTD.xml file as input.

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

Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 4.0
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Windows Phone
Disponible desde 8.1
Volver al principio
Mostrar: