It seems strange to be dynamically creating the xml document, and to then add the schema. You will need to know the structure of the xml document before creating the document, which sort of destroys the point of a schema. I can only presume you will be adding the schema prior to compiling the xml file.
Dim schema As New XmlSchemaSet()
schema.Add(
"namespace", ".xsd")Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.Schemas.Add(schema)
settings.ValidationType = ValidationType.Schema
Dim reader As XmlReader = XmlReader.Create(".xml", settings)
You will probably be working with a stream, so just change the first parameter of the XmlReader.Create object. You could also raise a ValidationCallback on the XmlDocument class, if this is your preferred method for reading an Xml document. This follows on from above:
Dim ev As New ValidationEventHandler(AddressOf ValidationCallback)Dim doc As New XmlDocument()
doc.Load(reader)
doc.Validate(ev)
End SubProtected Sub ValidationCallback(ByVal sender As Object, ByVal ev As ValidationEventArgs)
If ev.Severity = XmlSeverityType.Error Then
' ... error handling here
ElseIf ev.Severity = XmlSeverityType.Warning Then
' ... warning handling here.
End If
End Sub