我自己有点问题,我似乎无法弄清楚。我正在尝试使用 Microsoft 的以下说明以编程方式使用 DTD 验证生成的 XML 文件(Validation Using a DTD with XmlReader
到目前为止,这是我的代码:
Private Sub BTN_ValidateXMLdoc_Click(sender As Object, e As EventArgs) Handles BTN_ValidateXMLdoc.Click
Dim JobNumber As String = Me.HNF_JobName.Value
Dim XMLPath As String = "N:\" & JobNumber & "\" & JobNumber & ".xml"
' Set the validation settings.
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.DtdProcessing = DtdProcessing.Parse
settings.ValidationType = ValidationType.DTD
settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings
settings.ValidationFlags = XmlSchemaValidationFlags.ProcessInlineSchema
AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack
' Create the XmlReader object.
Dim reader As XmlReader = XmlReader.Create(XMLPath, settings)
' Parse the file.
While reader.Read()
End While
End Sub
' Display any validation errors.
Private Shared Sub ValidationCallBack(sender As Object, e As ValidationEventArgs)
MsgBox(String.Format("Validation Error: {0}", e.Message), MsgBoxStyle.OkOnly)
End Sub
现在....这就是我的问题。出于某种原因,ValidationCallBack EventHandler 永远不会被触发。如果在 reader.Read() 执行期间发生错误,则会引发异常错误。
如果我错了,请纠正我,但不应该调用 ValidationCallBack 子吗?
XML 文件中存在错误,但它不是由事件处理程序处理,而是抛出异常......
我对这里可能发生的事情持开放态度?