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 / October 2003

Tip: Looking for answers? Try searching our database.

Loading XML with missing DTD

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Morten Nielsen - 08 Oct 2003 15:26 GMT
I'm trying to load an XML file, that references a DTD without a relative
URL. This renders the error: Could not find file
"C:\WINNT\system32\capabilities_1_1_0.dtd".

Here's the XML I'm loading:
http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&REQUEST=GetCapa
bilities

Notice the DTD reference at the second line:
<!DOCTYPE WMT_MS_Capabilities SYSTEM "capabilities_1_1_0.dtd" [

What I try to do:
----------------------------------
  WebResponse myResponse = myRequest.GetResponse();
  Stream stream = myResponse.GetResponseStream();
  XmlDocument doc = new XmlDocument();
  doc.Load(stream);  // This is where it fails
----------------------------------

The code works fine when no DTD is specified.

Is there some way I can prevent the DTD checking, or make it read the dtd,
which is located relative to the XML file?

Any help is appreciated.

Regards
/Morten Nielsen
Email: http://www.iter.dk/contact.aspx
Morten Nielsen - 08 Oct 2003 22:32 GMT
> I'm trying to load an XML file, that references a DTD without a relative
> URL.

Sorry, I meant WITH a relative URL.

/Morten
Oleg Tkachenko - 09 Oct 2003 10:10 GMT
> I'm trying to load an XML file, that references a DTD without a relative
> URL. This renders the error: Could not find file
[quoted text clipped - 11 lines]
>    XmlDocument doc = new XmlDocument();
>    doc.Load(stream);  // This is where it fails

What's wrong with
doc.Load("http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&REQUEST=GetCapa
bilities
");

> Is there some way I can prevent the DTD checking, or make it read the dtd,
> which is located relative to the XML file?
No, you cannot prevent checking DTD, XmlTextWriter, which is always used
underneath always checks if DTD exists.
You problem is that you are providing XML as stream, so relative URI is
broken. Th easiest way is to provide URL to Load() method. If you need more
control over loading, use XmlTextReader and give him base URI or the XML you
are loading to allow proper URI resolving:
WebRequest myRequest =
WebRequest.Create("http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&REQUEST=GetCapa
bilities
");
WebResponse myResponse = myRequest.GetResponse();
Stream stream = myResponse.GetResponseStream();
XmlTextReader r = new
XmlTextReader("http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&REQUEST=GetCapa
bilities
",
stream);
XmlDocument doc = new XmlDocument();
doc.Load(r);
Signature

Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Morten Nielsen - 09 Oct 2003 11:04 GMT
> What's wrong with

doc.Load("http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&R
EQUEST=GetCapabilities");

I need to use a proxy to download data. XmlDocument doesn't have a Proxy
property like WebRequest does.

/Morten
Oleg Tkachenko - 09 Oct 2003 11:11 GMT
> doc.Load("http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&R
> EQUEST=GetCapabilities");
>
> I need to use a proxy to download data. XmlDocument doesn't have a Proxy
> property like WebRequest does.

So,

WebRequest myRequest =
WebRequest.Create("http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&REQUEST=GetCapa
bilities
");
myRequest.Proxy = ...
WebResponse myResponse = myRequest.GetResponse();
Stream stream = myResponse.GetResponseStream();
XmlTextReader r = new
XmlTextReader("http://maps1.intergraph.com/wms/ussample/request.asp?SERVICE=WMS&REQUEST=GetCapa
bilities
",
stream);
XmlDocument doc = new XmlDocument();
doc.Load(r);

Signature

Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Morten Nielsen - 09 Oct 2003 13:51 GMT
Thanks a lot.
It worked perfectly!

/Morten

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.