User-1895243249 posted
Howdy all,
Got myself a bit of a problem. I'm trying to validate an XML file using a DTD using the following code from http://msdn.microsoft.com/en-us/library/z2adhb2f.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
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
Now, for some reason, and I have no idea what the reason is (hence me posting here) if an error occurs while reader.Read(), instead of the ValidationCallBack sub being called, it throws an exception error. Now I could be wrong but if there is a validation
error while the reader.read() is executing, shouldn't the ValidationEventHandler be fired?