Groups | Blog | Home
all groups > dotnet xml > july 2006 >

dotnet xml : XmlDocument load question


supercodepoet NO[at]SPAM gmail.com
7/17/2006 8:52:14 AM
I have cXml document I want to load to parse. The document has a
DOCTYPE element that points to an external dtd via http. When the
document loads it trys a web request which I am assuming is to get the
dtd. We have a proxy and this throws and exception when trying to load
the document becuase it could not authenticate through the proxy. Is
there anyway I can turn off the download?
Martin Honnen
7/17/2006 6:05:02 PM


[quoted text, click to view]

XmlDocument has a property XmlResolver which you can set as needed to a
resolver so you can do e.g.
XmlDocument xmlDocument = new XmlDocument();
XmlUrlResover urlResolver = new XmlUrlResolver();
// set proxy and/or credentials on resolver as needed
xmlDocument.XmlResolver = urlResolver;
// now call Load method e.g.
xmlDocument.Load(@"file.xml");

--

Martin Honnen --- MVP XML
Thomas S
7/29/2006 4:37:10 PM
I had the same problem reading from a cxml doc. I did this:

XmlReaderSettings setts = new XmlReaderSettings();

setts.ValidationType = ValidationType.None; // no DTD validation

setts.XmlResolver = null; // do not even download the DTD

setts.ProhibitDtd = false; // to avoid an exception due to the presence of a
DTD in the XML doc

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

// pipe the stream to a higher level stream reader with the required
encoding format

StreamReader rstrm = new StreamReader(memstrm, encode);

// create the base reader object. necessary to apply the above settings

XmlReader xread = XmlReader.Create(rstrm, setts);




[quoted text, click to view]

AddThis Social Bookmark Button