I have a doc that that I am entering an incorrect value in a node that
expects an restricted enumeration yet I can't get the ValidationEventHandler
to fire. Shouldn't it fire if it finds an enumeration that's not listed in
the schema? I've also misspelled node tags and it still won't fire. Am I
missing something? Thanks.
Public Shared Function IsValid(ByVal cXML As String) As Boolean
_valid = True
Dim schemaColl As XmlSchemaCollection
schemaColl = New XmlSchemaCollection
schemaColl.Add(Nothing, New XmlTextReader("..\myXSD.xsd"))
Dim ioStream As Stream
ioStream = New MemoryStream(ASCIIEncoding.Default.GetBytes(cXML))
Dim xmlReader As XmlTextReader
xmlReader = New XmlTextReader(ioStream)
Dim xmlValidator As XmlValidatingReader
xmlValidator = New XmlValidatingReader(xmlReader)
xmlValidator.ValidationType = ValidationType.Schema
xmlValidator.Schemas.Add(schemaColl)
AddHandler xmlValidator.ValidationEventHandler, AddressOf ValidationError
While xmlValidator.Read()
End While
Return _valid
xmlReader.Close()
xmlValidator.Close()
End Function
Private Shared Sub ValidationError(ByVal sender As Object, ByVal args As
ValidationEventArgs)
_valid = False
End Sub