XmlReaderSettings.ProhibitDtd 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
Use XmlReaderSettings.DtdProcessing property instead.
注意
XmlReaderSettings.ProhibitDtd has been deprecated. Use DtdProcessing instead.
获取或设置一个值,该值指示是否禁用文档类型定义 (DTD) 处理。 此属性已过时。 请改用 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
属性值
如果禁用 DTD 处理,则为 true
;否则为 false
。 默认值为 true
。
- 属性
示例
以下示例使用 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
此示例使用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>
注解
设置为 “ true
设置为”时, XmlReader 会引发 XmlException 遇到任何 DTD 内容时。 如果您担心拒绝服务问题或您在处理不可信的源,则不要启用 DTD 处理。
如果启用了 DTD 处理,可以使用 XmlSecureResolver 限制 XmlReader 可以访问的资源。 还可以设计应用程序以使 XML 处理受内存和时间的约束。 例如,在 ASP.NET 应用程序中配置超时限制。
此属性已过时。 请改用 DtdProcessing。 如果已设置为 ProhibitDtd 其默认值 true
,则设置为 DtdProcessing Prohibit
。 如果已设置为 ProhibitDtd DtdProcessing false
Parse
.