I'm trying to write a generic VB.NET (VS2005) function to validate an XML document against an XSD. This works fine until I use an XSD with a relative path include like:
<xs:include schemaLocation="test.02.xsd" />
It can never seem to find what is included in any secondary documents. Here is my original function below. I've been playing with XmlUrlResolver() but I cannot seem to make any progress using that either. Any help here would be greatly appreciated.
Private Sub ValidatingProcess(ByVal XSDPath As String, ByVal XMLPath As String)
Try
Me.Reader = New XmlTextReader(XMLPath)
Dim SR As New StreamReader(XSDPath)
Dim Schema As New XmlSchema()
Schema = XmlSchema.Read(SR, New ValidationEventHandler(AddressOf ReaderSettings_ValidationEventHandler))
Dim ReaderSettings As New XmlReaderSettings()
ReaderSettings.ValidationType = ValidationType.Schema
ReaderSettings.Schemas.Add(Schema)
AddHandler ReaderSettings.ValidationEventHandler, AddressOf ReaderSettings_ValidationEventHandler
Dim objXmlReader As XmlReader = XmlReader.Create(Reader, ReaderSettings)
While objXmlReader.Read()
End While
Catch AccessEx As UnauthorizedAccessException
Throw AccessEx
Catch Ex As Exception
Throw Ex
End Try
End Sub