I have the following code:
I have a local copy of the DTD that I need to validate incoming XML
documents against.
The XML document has the <!DOCTYPE myname SYSTEM "myfile.dtd "> define.
When the following code is executed the XML gets resolved through the
XMLResolver and gets correctly validated against the locally stored DTD
file.
The problem occurs when the incoming XML contains no DOCTYPE attribute. The
resolver code never gets called and the validation does not occur at all.
What am I doing wrong here? Is that a bug and there is no way to enforce
the DTD even if the icoming XML file does not specify the DTD file?
XmlDocument doc = new XmlDocument();
XmlValidatingRe ader reader = new XmlValidatingRe ader(new
XmlTextReader(s tream));
reader.XmlResol ver = new MyDTDResolver() ;
reader.Validati onType = ValidationType. DTD;
doc.Load(reader );
The XML document's stream is contained in the stream variable
Here is MyDTDResolver declaration:
private class MyDTDResolver:X mlUrlResolver
{
public override object GetEntity(Uri absoluteUri, string role, Type
ofObjectToRetur n)
{
return (returns a stream of the local copy of the DTD document that I
validate XML against)
}
}