I have a web service that processes an HTTP request. The document it receives has an embeded DOCTYPE that specifies a .dtd file. I wish to use a newer XML schema validation file made for when newer devices connect to my service.
I can successfully ignore the validation that goes on in the .dtd file, but the .dtd file must exist on my local hard drive. I want to remove these obsolete files, and have not found a way.
Sample XML document I am processing:
<?xml version="1.0" encoding="us-ascii" standalone="no"?>
<!DOCTYPE SomeMessage SYSTEM "SomeMessage.dtd">
<SomeMessage>data</SomeMessage>
The function that I am using to open the document:
private void LoadXmlDoc(XmlTextReader myXmlTextReader)
{
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.Schemas.Add(null, MyGoodSchemaFile);
readerSettings.DtdProcessing = DtdProcessing.Ignore;
readerSettings.XmlResolver = null; // Added as a test.
readerSettings.ValidationEventHandler += ValidationEventHandle;
XmlReader myXmlReader = XmlReader.Create(myXmlTextReader, readerSettings);
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.XmlResolver = null; // Added as a test.
myXmlDocument.Load(myXmlReader); // Exception thrown here!
}
The exception that is caught:
System.IO.FileNotFoundException: Could not find file 'c:windowssystem32inetsrvSomeMessage.dtd'.
File name: 'c:windowssystem32inetsrvSomeMessage.dtd'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
The content of the SomeMessage.dtd file is not used--it is ignored as I desire. However, the dummy file "c:windowssystem32inetsrvSomeMessage.dtd" must exist, otherwise the exception is thrown.
I am running on Windows 7, using Visual Studio 2010 and .Net 4.0
How can I ignore the embeded .dtd and also not require a dummy .dtd file to be installed on my computer?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…