Validating XML using relative DTD DOCTYPE


New member
Jan 10, 2011
Programming Experience
I want to validate an XML file usng a relative PUBLIC DTD in the DOCTYPE.

The following code produces an exception which states that the DTD cannot be found. The path is for where the XML file is located and not where the DTD is located. It seems that the XmlUrlResolver is not behaving as I would expect.

If I change the DTD declation in the XML file to a absolute path, the XML file will validate.

How can I get the validation to work using a relative path?

(I would like a solution for Framework1.1, but any Framework solution would be appreciated)

Public Shared Sub DoThis(ByVal fn As String)
Dim resolver As XmlUrlResolver = New XmlUrlResolver
Dim mainURI As Uri = New Uri("file:///C:/DITADTDs/AE11/reference.dtd")
resolver.ResolveUri(mainURI, "reference.dtd")
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.DtdProcessing = DtdProcessing.Parse
settings.ValidationType = ValidationType.DTD
settings.XmlResolver = resolver
AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack
Dim reader As XmlReader = XmlReader.Create(fn, settings)
While reader.Read()
End While
Catch ex As Exception
End Try
End Sub

Top Bottom