Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / November 2005

Tip: Looking for answers? Try searching our database.

Suppressing DTD look-up via web access when loading XmlDocument

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
emma_middlebrook@fastmail.fm - 22 Nov 2005 12:08 GMT
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.
emma_middlebrook@fastmail.fm - 26 Nov 2005 13:24 GMT
I still am looking for a solution if anyone would be kind enough to
help.

Thanks

Emma

> Hi
>
[quoted text clipped - 16 lines]
>
> Emma.
Truong Hong Thi - 28 Nov 2005 07:35 GMT
Hi,

>I also set its XmlResolver to
>null but to no avail.
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
emma_middlebrook@fastmail.fm - 28 Nov 2005 21:57 GMT
> Hi,
>
[quoted text clipped - 33 lines]
> Thi
> http://thith.blogspot.com

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
emma_middlebrook@fastmail.fm - 28 Nov 2005 23:13 GMT
> 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.

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! :-)
emma_middlebrook@fastmail.fm - 28 Nov 2005 23:36 GMT
> 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! :-)

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!) :-)
emma_middlebrook@fastmail.fm - 28 Nov 2005 23:37 GMT
Not that anyone's reading, but I meant, this post:

http://groups.google.co.uk/group/microsoft.public.dotnet.xml/browse_frm/thread/f
476f6a3fd610e78/09c99a4917a3c416?q=loading+xml+document+no+dtd&rnum=9#09c99a4917
a3c416


Emma
ship261 - 30 Nov 2005 20:58 GMT
Well let me just say that its unique

---------------------------------
http://community.ihostasp.ne
ASP.NET Developer Community

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.