XmlReaderSettings.DtdProcessing Proprietà

Definizione

Ottiene o imposta un valore che determina l'elaborazione dei DTD.

public:
 property System::Xml::DtdProcessing DtdProcessing { System::Xml::DtdProcessing get(); void set(System::Xml::DtdProcessing value); };
public System.Xml.DtdProcessing DtdProcessing { get; set; }
member this.DtdProcessing : System.Xml.DtdProcessing with get, set
Public Property DtdProcessing As DtdProcessing

Valore della proprietà

Uno dei valori di enumerazione che determina l'elaborazione dei DTD. Il valore predefinito è Prohibit.

Esempio

Nell'esempio seguente viene convalidato un file XML usando un file DTD.

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);
  }
}
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO

public class Sample 

  public shared sub Main() 

    ' Set the validation settings.
    Dim settings as XmlReaderSettings = new XmlReaderSettings()
    settings.DtdProcessing = DtdProcessing.Parse
    settings.ValidationType = ValidationType.DTD
    AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack
 
    ' Create the XmlReader object.
    Dim reader as XmlReader = XmlReader.Create("itemDTD.xml", settings)

    ' Parse the file. 
    while reader.Read()
    end while
    
  end sub

  ' Display any validation errors.
  private shared sub ValidationCallBack(sender as object, e as ValidationEventArgs) 
    Console.WriteLine("Validation Error: {0}", e.Message)
  end sub
end class

L'esempio usa il itemDTD.xml file come 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>

Commenti

La convalida DTD (Document Type Definition) viene implementata usando i vincoli di validità definiti nella raccomandazione W3C Extensible Markup Language (XML) 1.0 (quarta edizione). I DTD usano una grammatica formale per descrivere la struttura e la sintassi dei documenti XML conformi; specificano il contenuto e i valori consentiti per il documento XML.

La DtdProcessing proprietà può avere uno dei valori seguenti:

Per eseguire la convalida su un DTD, XmlReader usa il DTD definito nella dichiarazione DOCTYPE di un documento XML. La dichiarazione DOCTYPE può puntare a un DTD inline oppure può essere un riferimento a un file DTD esterno. Per convalidare un file XML rispetto a un DTD:

Important

Se la DtdProcessing proprietà è impostata su DtdProcessing.Ignore, l'oggetto XmlReader non segnala i DTD. Ciò significa che DTD/DOCTYPE andrà perso nell'output.

Si applica a