I'm developing a VB Web Application in .NET3.5 using Visual Studio 2008.
I'm having difficulty in validating some XML as a string before I add it to a HTML form to post to a 3rd party. I have an XML schema file from the 3rd party to validate against and at this point I'd like the application to perform the validation before each post.
After searching I've found references to a XmlValidatingReader but this is obsolete and I'm having difficulty finding another way to do it.
Also all the good examples are in C# - for now I'm stuck with VB. This is what I have so far which I'm looking for help with!
Public Function ValidateXML(ByVal strXML As String) As Boolean
' er how do I get the schema file into here?
Dim schema As XmlReader
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.Schemas.Add("", schema)
settings.ValidationType = ValidationType.Schema
' When I use LoadXML to get the string I can't use the settings object above to get the schema in??
Dim document As XmlDocument = New XmlDocument()
document.LoadXml(strXML)
document.Validate(AddressOf ValidationEventHandler)
End Function
Private Sub ValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)
' Gonna return false here but haven't got to it yet! Prob set a variable for use above
End Sub
Thanks