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. ::..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s