Hello. I'm new to using XML/HTML. I am trying to learn to validate
xml sample docs against schemas. I have an XML and Schema file (.xsd)
saved to my desktop. Below is my sample code, which is borrowed from
the .NET help files. It blows up when I try to refererence a schema
that is on my desktop.
If you can, please correct my misunderstanding about referencing
schemas, as evidenced in the below example. Am I attempting the
impossible, or just attempting the possible wrongly?
Thanks for any help,
MWG
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Public Class validationhandler
Public Shared Sub callvalreader()
Dim stream As New FileStream("C:\Documents and
Settings\mgoold\Desktop\Input\xmlexample.xml", FileMode.Open)
Dim vr As New XmlValidatingReader(stream, XmlNodeType.Element,
Nothing)
'HERE IS WHERE THE CODE THROWS AN ERROR:
vr.Schemas.Add("\\Documents and
Settings\mgoold\Desktop\Input\Schematrial.xsd", "//C:/Documents and
Settings/mgoold/Desktop/Input/Schematrial.xsd")
vr.ValidationType = ValidationType.Schema
AddHandler vr.ValidationEventHandler, AddressOf
ValidationHandler
While vr.Read()
End While
Console.WriteLine("Validation finished")
End Sub
Public Shared Sub ValidationHandler(ByVal sender As Object, ByVal
args As ValidationEventArgs)
Console.WriteLine("***Validation error")
Console.WriteLine("Severity:{0}", args.Severity)
Console.WriteLine("Message:{0}", args.Message)
End Sub
End Class