Xml ProhibitDtd error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • agda.karlberg@gmail.com

    Xml ProhibitDtd error

    Hi,

    I'm trying to validate an xml document against a schema. I get an
    exception saying "For security reasons DTD is prohibited in this XML
    document. To enable DTD processing set the ProhibitDtd property on
    XmlReaderSettin gs to false and pass the settings into XmlReader.Creat e
    method.", however I have set it to false so not sure what else to try.

    Here's my code:

    FileStream fs = File.Open(myFil ePath, FileMode.Open);

    XmlReaderSettin gs settings = new XmlReaderSettin gs();

    settings.Prohib itDtd = false;
    settings.Schema s.Add(null, "http://www.w3.org/TR/xmldsig-core/xmldsig-
    core-schema.xsd");

    settings.Valida tionType = ValidationType. Schema;
    settings.Valida tionEventHandle r += new
    System.Xml.Sche ma.ValidationEv entHandler(sett ings_Validation EventHandler);

    XmlReader reader = XmlReader.Creat e(fs, settings);

    while (reader.Read())

    Am I missing something obvious?

    Many thanks,

    AK
  • Martin Honnen

    #2
    Re: Xml ProhibitDtd error

    agda.karlberg@g mail.com wrote:
    XmlReaderSettin gs settings = new XmlReaderSettin gs();
    >
    settings.Prohib itDtd = false;
    settings.Schema s.Add(null, "http://www.w3.org/TR/xmldsig-core/xmldsig-
    core-schema.xsd");
    That schema has a DOCTYPE declaration so you need e.g.
    XmlReaderSettin gs xrs = new XmlReaderSettin gs();
    xrs.ProhibitDtd = false;
    settings.Schema s.Add(null,
    XmlReader.Creat e("http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd",
    xrs));




    --

    Martin Honnen --- MVP XML

    Comment

    • agda.karlberg@gmail.com

      #3
      Re: Xml ProhibitDtd error

      On Oct 16, 11:53 am, Martin Honnen <mahotr...@yaho o.dewrote:
      >
      That schema has a DOCTYPE declaration so you need e.g.
         XmlReaderSettin gs xrs = new XmlReaderSettin gs();
         xrs.ProhibitDtd = false;
         settings.Schema s.Add(null,
      XmlReader.Creat e("http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd",
      xrs));
      Works perfectly, thank you so much!

      AK

      Comment

      Working...