I am simply playing around with xml schemas to understand them better and came across this article -
The trouble is in this example no matter what changes I make to the XML document it never raises the validationEvent Handler.
Here is my code -
The namespaces are correct and I can assure you that SE.xml should not validate against UserConfigSchem a.xsd as I have thrown in some random new elements.
Can anyone point in the righ direction? What am I doing wrong?
The trouble is in this example no matter what changes I make to the XML document it never raises the validationEvent Handler.
Here is my code -
Code:
Public Shared Sub ValTest()
Dim sc As XmlSchemaSet = New XmlSchemaSet()
' Add the schema to the collection.
sc.Add("urn:bookstore-schema", System.Web.Hosting.HostingEnvironment.MapPath("~\UserConfigSchema.xsd"))
' Set the validation settings.
Dim settings As XmlReaderSettings = New XmlReaderSettings()
settings.ValidationType = ValidationType.Schema
settings.Schemas = sc
AddHandler settings.ValidationEventHandler, AddressOf ValidationEventHandler
' Create the XmlReader object.
Dim reader As XmlReader = XmlReader.Create(System.Web.Hosting.HostingEnvironment.MapPath("~\Default Profiles\SE.xml"), settings)
' Parse the file.
While reader.Read()
End While
End Sub
Private Shared Sub ValidationEventHandler(ByVal sender As Object, ByVal args As ValidationEventArgs)
'Just for testing
Dim obj = sender
Dim obj2 = args
End Sub
Can anyone point in the righ direction? What am I doing wrong?
Comment