sample XmlReader Validation Handler

”’ <summary>
”’ XmlReader Validation Handler
”’ </summary>
”’ <param name=”sender”></param>
”’ <param name=”e”></param>
”’ <remarks>not used, not ready</remarks>
Sub oXmlReaderSettingsValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)
If e.Severity = XmlSeverityType.Warning Then
Console.Write(“WARNING: “)
ElseIf e.Severity = XmlSeverityType.Error Then
Console.Write(“ERROR: “)
End If
End Sub

..:: Whereever you go, stay in touch. Download toolbar now! It´s free, private and secure. ::..


validate XML File against XSD File

”’ <summary>
”’ validates XML File against XSD File
”’ </summary>
”’ <param name=”sXmlFile”>xml data</param>
”’ <param name=”sXSDFile”>external xml schema</param>
”’ <returns>true no errors, false errors</returns>
”’ <remarks></remarks>
Public Function ValidateXMLFileExternalXSD(ByVal sXmlFile As String, ByVal sXSDFile As String)
Dim oXmlReaderSettings As XmlReaderSettings = New XmlReaderSettings()
oXmlReaderSettings.Schemas.Add(“;, sXSDFile)
AddHandler oXmlReaderSettings.ValidationEventHandler, New ValidationEventHandler(AddressOf oXmlReaderSettingsValidationEventHandler)
oXmlReaderSettings.ValidationFlags = oXmlReaderSettings.ValidationFlags And XmlSchemaValidationFlags.ReportValidationWarnings
oXmlReaderSettings.ValidationType = ValidationType.Schema
Dim reader As XmlReader = XmlReader.Create(sXmlFile, oXmlReaderSettings)
Dim oDom As New XmlDocument
Catch ex As XmlException
Console.WriteLine(“XmlDocumentValidationExample.XmlException: {0}”, ex.Message)
Return False
Catch ex As XmlSchemaValidationException
Console.WriteLine(“XmlDocumentValidationExample.XmlSchemaValidationException: {0}”, ex.Message)
Return False
Catch ex As Exception
Console.WriteLine(“XmlDocumentValidationExample.Exception: {0}”, ex.Message)
Return False

End Try
Return True
End Function

..:: Whereever you go, stay in touch. Download toolbar now! It´s free, private and secure. ::..