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?
XML does not require a DTD. When you are experimenting with XML, or when you are working with small XML files, creating DTDs may be a waste of time.
Cause: The most common reason for this error is because the user's ISP is trying to be helpful and is sending the user to a friendly DNS failure page instead of letting it just fail when the DNS entry is not valid.
A DTD defines the structure and the legal elements of an XML document. Because HTML 4.01 was based on the Standard Generalised Markup Language (SGML), referring to a DTD in the DOCTYPE declaration was necessary.
It defines the document structure with a list of legal elements. A DTD can be declared inline in your XML document, or as an external reference. By default, NBi doesn't execute DTD commands in the XML file describing the test-suite. The main reason is security.
After some more digging, maybe you should set the XmlResolver property of the XmlReaderSettings object to null.
'The XmlResolver is used to locate and open an XML instance document, or to locate and open any external resources referenced by the XML instance document. This can include entities, DTD, or schemas.'
So the code would look like this:
XmlReaderSettings settings = new XmlReaderSettings(); settings.XmlResolver = null; settings.DtdProcessing = DtdProcessing.Parse; XmlDocument doc = new XmlDocument(); using (StringReader sr = new StringReader(xml)) using (XmlReader reader = XmlReader.Create(sr, settings)) { doc.Load(reader); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With