XmlReaderSettings.ProhibitDtd Vlastnost

Definice

Upozornění

Use XmlReaderSettings.DtdProcessing property instead.

Upozornění

XmlReaderSettings.ProhibitDtd has been deprecated. Use DtdProcessing instead.

Získá nebo nastaví hodnotu určující, zda zakázat zpracování definice typu dokumentu (DTD). Tato vlastnost je zastaralá. Místo toho použijte DtdProcessing.

public:
 property bool ProhibitDtd { bool get(); void set(bool value); };
[System.Obsolete("Use XmlReaderSettings.DtdProcessing property instead.")]
public bool ProhibitDtd { get; set; }
[System.Obsolete("XmlReaderSettings.ProhibitDtd has been deprecated. Use DtdProcessing instead.")]
public bool ProhibitDtd { get; set; }
public bool ProhibitDtd { get; set; }
[<System.Obsolete("Use XmlReaderSettings.DtdProcessing property instead.")>]
member this.ProhibitDtd : bool with get, set
[<System.Obsolete("XmlReaderSettings.ProhibitDtd has been deprecated. Use DtdProcessing instead.")>]
member this.ProhibitDtd : bool with get, set
member this.ProhibitDtd : bool with get, set
Public Property ProhibitDtd As Boolean

Hodnota vlastnosti

Boolean

true zakázat zpracování DTD; jinak false. Výchozí formát je true.

Atributy

Příklady

Následující příklad ověří data pomocí DTD.

#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;
}
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

Příklad používá jako vstup soubor itemDTD.xml.

<!--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>

Poznámky

Pokud je nastavená hodnota true, XmlReader vyvolá XmlException se, když dojde k jakémukoli obsahu DTD. Nepovolujte zpracování DTD, pokud máte obavy o problémy s odepřením služby nebo pokud pracujete s nedůvěryhodnými zdroji.

Pokud máte povolené zpracování DTD, můžete použít XmlSecureResolver k omezení prostředků, ke kterým XmlReader má přístup. Aplikaci můžete také navrhnout tak, aby zpracování XML bylo omezené na paměť a čas. Můžete například nakonfigurovat limity časového limitu ve vaší ASP.NET aplikaci.

Tato vlastnost je zastaralá. Místo toho použijte DtdProcessing. Pokud jste nastavili ProhibitDtd výchozí hodnotu true nastavenou DtdProcessing na Prohibit. Pokud jste nastavili ProhibitDtd nastavenou DtdProcessing false hodnotu Parse.

Platí pro