logo

Previous Thread:   Xpath newb question

11/22/2005 4:08:59 AM    Suppressing DTD look-up via web access when loading XmlDocument
Hi  
  
In one of our test suites we load an xml document (it's actually .svg).  
  
I'm trying to find some way of stopping the eventual call to  
  
HttpWebRequest.GetResponse which I presume it's doing when going to get  
  
the DTD at "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd".  
  
The result is a time-out because this machine is isolated from the  
  
database, the web, everything really :-)  
  
I tried to pass XmlDocument a non-validating reader e.g. XmlTextReader  
  
but the web request was still attempted. I also set its XmlResolver to  
  
null but to no avail.  
  
Would anyone be able to advise me on how to solve this problem? MSDN  
  
seems to suggest the approaches I've already tried so now I'm a little  
  
stuck!  
  
Thanks very much,  
  
Emma.

11/26/2005 5:24:04 AM    Re: Suppressing DTD look-up via web access when loading XmlDocument
I still am looking for a solution if anyone would be kind enough to  
  
help.  
  
Thanks  
  
Emma  
  
emma_middlebrook@fastmail.fm wrote:

11/27/2005 11:35:49 PM    Re: Suppressing DTD look-up via web access when loading XmlDocument
Hi,  
  
I am afraid you have to implement your own resolver.  
  
The dtd is on w3c site at http://www.w3.org/TR/SVG11/svgdtd.html. Try  
  
downloading it at  
  
http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat-20030114.dtd and save  
  
it to your local machine.  
  
To instruct .net to look for the dtd file on local disk, define your  
  
resolver:  
  
public class MyResolver : XmlUrlResolver  
  
{  
  
public override Uri ResolveUri(Uri baseUri, string relativeUri)  
  
{  
  
// you could check for equality instead of ending with  
  
if (relativeUri.ToUpper().EndsWith(".DTD"))  
  
{  
  
return new Uri("relative/absolute path to DTD on local");  
  
}  
  
return base.ResolveUri (baseUri, relativeUri);  
  
}  
  
}  
  
Use the resolver with XmlDocument and/or XmlReader. Example:  
  
XmlDocument doc = new XmlDocument();  
  
doc.XmlResolver = new MyResolver();  
  
doc.Load("sample.svg");  
  
Hope it helps,  
  
Thi  
  
http://thith.blogspot.com

11/28/2005 1:57:06 PM    Re: Suppressing DTD look-up via web access when loading XmlDocument
Truong Hong Thi wrote:  
  
Thanks Truong for your reply.  
  
I will give your suggestion a go once I get into work (although you  
  
will agree that this shouldn't be the only way to do this - something  
  
simpler surely?!).  
  
In fact, encouraged by your reply, I have had just had another look  
  
through the documentation and I think XmlNodeReader might be the most  
  
basic class to use so will try that too.  
  
Good luck with your new blog!  
  
Does anyone else find the XmlTextReader documentation confusing -  
  
here's a little synopsis below. Am I the only one who is confused when  
  
reading it?  
  
XmlTextReader documentation ...  
  
First of all it says:  
  
1. "XmlTextReader checks the DTD for well-formedness, but does not  
  
validate using the DTD."  
  
then it says:  
  
2. "DTD processing is enabled by default. ... Set the ProhibitDtd  
  
property to true to disable DTD processing." (This is new in 2.0.)  
  
then it says:  
  
3. "XML data can include references to external resources such as a DTD  
  
file. By default external resources are resolved using an  
  
XmlUrlResolver object."  
  
then it says:  
  
4. "Do not allow the XmlReader to open any external resources by  
  
setting the XmlResolver property to a null reference."  
  
So I thought if it wasn't going to use the DTD (point 1) then it  
  
shouldn't need to use its XmlUrlResolver to go and get it. So why does  
  
it?  
  
Point 2 seems to suggest that there is a difference between processing  
  
a DTD and actually using it to validate something: well what's the  
  
point in processing it if it's not going to be using it to validate  
  
something?!  
  
Point 3 is fair enough but point 4 is not true; the request is still  
  
made for the DTD.  
  
Moan over.  
  
Emma

11/28/2005 3:13:08 PM    Re: Suppressing DTD look-up via web access when loading XmlDocument
However a further look shows that I'm in a catch-22 situation! To use  
  
an XmlNodeReader one has to first have an XmlNode and I wonder how we  
  
get one of those! :-)

11/28/2005 3:36:04 PM    Re: Suppressing DTD look-up via web access when loading XmlDocument
And now time to declare that:  
  
i.e. point 4 was correct after all: before, I was setting the  
  
XmlDocument's XmlResolver to null not the XmlTextReader's XmlResolver.  
  
And, if I'd searched properly, I would have found this post mentioning  
  
that solution and Truong's solution as well!  
  
Problem solved!  
  
Emma  
  
PS I still think the docs on XmlTextReader are a little misleading (but  
  
then, so was my post!) :-)

11/28/2005 3:37:45 PM    Re: Suppressing DTD look-up via web access when loading XmlDocument
Not that anyone's reading, but I meant, this post:  
  
http://groups.google.co.uk/group/microsoft.public.dotnet.xml/browse_frm/thread/f476f6a3fd610e78/09c99a4917a3c416?q=loading+xml+document+no+dtd&rnum=9#09c99a4917a3c416  
  
Emma

11/30/2005 2:58:14 PM    True
Well let me just say that its unique.  
  
----------------------------------  
  
http://community.ihostasp.net  
  
ASP.NET Developer Community