validate XML File against inline Schema

”’ <summary>
”’ validates XML File against inline Schema
”’ </summary>
”’ <param name=”sXmlFile”>xml File mit Schema und Daten</param>
”’ <returns>true no errors, false errors</returns>
”’ <remarks>not used, not ready</remarks>
”’
Public Function ValidateXMLFileInternalXSD(ByVal sXmlFile As String) As Boolean
Try
Dim oXmlReaderSettings As New XmlReaderSettings()
oXmlReaderSettings.ValidationType = ValidationType.Schema
oXmlReaderSettings.ValidationFlags = oXmlReaderSettings.ValidationFlags Or XmlSchemaValidationFlags.ProcessInlineSchema
oXmlReaderSettings.ValidationFlags = oXmlReaderSettings.ValidationFlags Or XmlSchemaValidationFlags.ReportValidationWarnings
AddHandler oXmlReaderSettings.ValidationEventHandler, AddressOf oXmlReaderSettingsValidationEventHandler
Dim reader As XmlReader = XmlReader.Create(sXmlFile, oXmlReaderSettings)
‘ parse reader
While (reader.Read())
End While
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. ::..

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)
Try
Dim oXmlReaderSettings As XmlReaderSettings = New XmlReaderSettings()
oXmlReaderSettings.Schemas.Add(“http://www.tempuri.org&#8221;, 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
oDom.Load(reader)
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
Finally

End Try
Return True
End Function

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