XmlTextReader not able to find DTD file

  • Thread starter Thread starter Eivind Gussiås Løkseth
  • Start date Start date
E

Eivind Gussiås Løkseth

I'm having trouble with an ASP.NET application used to receive XML content
over http. The application gets the XML content as the HttpWebRequest
content, and the XML document references a DTD file for XML validation. I
have the DTD file in the Bin folder, but that's not where .NET expects it to
be.

When debuggin, I found that the path where .NET was looking for the DTD
file, was the path of the IIS process (C:\Windows\System32\inetsrv\), so I
copied the DTD file to that folder, and everything seemed to work just fine.
And it did so in the production environment too, until it started to look
for the DTD file from some folder beneath the ftproot folder! I suppose it's
the last (current) folder used by IIS for some FTP session.

I guess I need a way to explicitly tell where the DTD file is. The exception
occures when i call the Load() method of an XmlDocument object. Can someone
help me out with this?

BTW, the XML content looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE MSGLST SYSTEM
"pswincom_report_request.dtd">
<MSGLST><MSG><ID>1</ID><REF>98183520</REF><RCV>4793213244</RCV><STATE>DELIVRD</STATE></MSG></MSGLST>
 
Eivind said:
I guess I need a way to explicitly tell where the DTD file is. The
exception occures when i call the Load() method of an XmlDocument
object. Can someone help me out with this?

BTW, the XML content looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE MSGLST SYSTEM
"pswincom_report_request.dtd">
<MSGLST><MSG><ID>1</ID><REF>98183520</REF><RCV>4793213244</RCV><STATE>DELIVRD</STATE></MSG></MSGLST>

You can set a custom XmlResolver:
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.xmlresolver.aspx
One way to do that is to subclass XmlUrlResolver where the subclass
overrides the GetEntity and ResolveUri methods and makes sure that for
the URI pswincom_report_request.dtd the DTD is loaded from the location
where you stored it.
 
Back
Top