Hi,
Here's my problem code:
....
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Document;
settings.CheckCharacters = false;
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreWhitespace = true;
settings.ProhibitDtd = false;
System.IO.FileStream stream = new System.IO.FileStream(path,
FileMode.Open, FileAccess.Read, FileShare.Read);
XmlReader reader = XmlReader.Create(stream, settings);
XmlDocument myDocument = new XmlDocument();
try
{
myDocument.Load(reader);
}
catch (Exception e)
{
....
The code works if "path" refers to a UTF-8 encoded XML file. If it
refers to a UTF-16 encoded file, myDocument.Load(reader) throws an
exception. Also, if I replace myDocument.Load(reader) with
myDocument.Load(path), the code works for both UTF-8 and UTF-16, but I
can't do that because I need the XmlReaderSettings.
The message and stack trace are:
An error has occurred while opening external DTD 'file:///C:/Documents
and Settings/myName/folder1/.../folder6/folder7/someFileName.dtd':
Could not find a part of the path 'C:\\Documents and Settings\\myName\
\folder1\\...
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.DtdParserProxy_PushEx ternalSubset
(String systemId, String publicId)
...
That's not the correct path to the DTD. The path is relative to the
location of the XML file.
The XML contains:
<!DOCTYPE myType SYSTEM "folder6/folder7/someFileName.dtd">
This exact tag appears in UTF-8 encoded XML files in an identical
directory structure, and they don't produce this error.
Any help would be much appreciated.
Thanks,
Daniel Sheiner