我收到错误
文档上的 XmlSchemaSet 为 null 或其中没有架构。在调用 Validate 之前提供架构信息。
但是我的架构文件位于指定的位置:
C:\InvSchema.xsd
没有传递特定的命名空间,所以我将其设置为空。
那么,为什么我会收到此错误?
我还需要知道 xml 模式是否已成功验证,但 validate 函数不返回确认它的布尔值。
我如何从中获得该值
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