Prevent DTD download when parsing XML

前端 未结 5 832
北恋
北恋 2020-12-09 01:44

When using XmlDocument.Load , I am finding that if the document refers to a DTD, a connection is made to the provided URI. Is there any way to prevent this from happening?

5条回答
  •  臣服心动
    2020-12-09 02:38

    The document being loaded HAS a DTD.

    With:

    settings.ProhibitDtd = true;
    

    I see the following exception:

    Service cannot be started. System.Xml.XmlException: For security reasons DTD is prohibited in this XML document. To enable DTD processing set the ProhibitDtd property on XmlReaderSettings to false and pass the settings into XmlReader.Create method.

    So, it looks like ProhibitDtd MUST be set to true in this instance.

    It looked like ValidationType would do the trick, but with:

    settings.ValidationType = ValidationType.None;
    

    I'm still seeing a connection to the DTD uri.

提交回复
热议问题