473,326 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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.

Nov 23 '05 #1
7 1710
I still am looking for a solution if anyone would be kind enough to
help.

Thanks

Emma

em**************@fastmail.fm wrote:
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.


Nov 26 '05 #2
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/D...t-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

Nov 28 '05 #3
Truong Hong Thi wrote:
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/D...t-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


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

Nov 28 '05 #4
> 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! :-)

Nov 28 '05 #5
> 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!) :-)

Nov 28 '05 #6
Not that anyone's reading, but I meant, this post:

http://groups.google.co.uk/group/mic...c99a4917a3c416

Emma

Nov 28 '05 #7
Well let me just say that its unique.

----------------------------------
http://community.ihostasp.net
ASP.NET Developer Community
Nov 30 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Phil Powell | last post by:
How do I suppress the lines PHP normally delivers to stdout (your browser) if I am doing command-line PHP? e.g. stuff.php: <? echo 'Hello World'; ?> Calling it from a Red Hat 7.3...
3
by: inhahe | last post by:
Hi i'm a newbie at this and probably always will be, so don't be surprised if I don't know what i'm talking about. but I don't understand why regex look-behinds (and look-aheads) have to be...
2
by: Paul Thompson | last post by:
Can I use JavaScript in some way to entirely suppress and control the tab key, so that I perform all functions that tab performs? I can detect the tab key, but can't seem to eliminate it.
7
by: Kenneth P | last post by:
Hi, I've seen many Internet sites that suppress the URL or show the same URL all the time your moving around different pages. You'll only see the real page with it's path in the statusbar way...
1
by: Shell | last post by:
Hi, I have an application written in ASP.NET 2.0, I would like it's GUI especially the webpart to look like windows xp like transparent look or 3D look. I have looked at option of Borderstyle...
3
by: b747_440 | last post by:
Hello Newsgroup, I try to resize and move a picturebox. However, after each operation the picture box is being redrawn. This causes flickering. Is it possible to suppress the first redraw and draw...
20
by: Maurice | last post by:
Hi all, I have an application, designed in Visual Studio 2005, which will run mainly on Windows XP computers. If I run the application on a Windows XP computer having the Windows XP Theme...
6
by: Michael B Allen | last post by:
Hi, I have a macro that looks like the following: #define MMSG msgno_loc0(LOC0, LOC1) && msgno_mmsg0 which if used in some code like: MMSG("foo=%s", foo);
5
by: Don Li | last post by:
Hi, A web app server package that I'm using includes a bunch of open source UI components (heavy with javascripts). Inevitably it has bugs, e.g. "undefined" is null or not an object. This...
2
by: puzzled | last post by:
I have "Find" buttons throughout my database, each with focus on a different field (they were created with the wizard, then the focus set to the corresponding field with VB). If i press a find button...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.