0
我收到錯誤XML驗證錯誤:驗證對空模式設置
The XmlSchemaSet on the document is either null or has no schemas in it. Provide schema information before calling Validate.
但我所在的位置中的架構文件中指定:
C:\InvSchema.xsd
有沒有通過特定的命名空間,所以我把它設置爲空。
那麼,爲什麼我會得到這個錯誤?
我還需要知道xml模式是否已成功驗證,但驗證函數沒有返回確認它的布爾值。
如何從
InvImp.Validate(evtHandler)
獲得該值?
下面是代碼:
Private Function ValidateSchema() As Boolean
Try
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.Schemas.Add("", "C:\InvSchema.xsd")
settings.ValidationType = ValidationType.Schema
Dim evtHandler As ValidationEventHandler = New ValidationEventHandler(AddressOf ValidationEventHandler)
Dim reader As XmlReader = XmlReader.Create(_fileName, settings)
Dim InvImp As XmlDocument = New XmlDocument
InvImp.Validate(evtHandler)
ValidateSchema = True
Catch ex As Exception
Throw ex
ValidateSchema = False
End Try
End Function
Shared Sub ValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)
Select Case e.Severity
Case XmlSeverityType.Error
Library.Log("Schema validation failed error " & e.Message, LogType.ERRORLOG, ImportType.InvcIMP)
Case XmlSeverityType.Warning
Library.Log("Schema validation warning " & e.Message, LogType.EVENTLOG, ImportType.InvcIMP)
End Select
End Sub