Heres a solution validating against a dtd. Should be easy to change to schema.
using System.Xml;
using System.Xml.Schema;
public static void handle_validation(object s, ValidationEventArgs a)
{
throw new Exception("The file could not be validatet " + a.Message);
}
try
{
XmlTextReader r = new XmlTextReader(path); //insert path to xml file here
XmlValidatingReader v = new XmlValidatingReader(r); // new Instance of validating reader
v.ValidationType = ValidationType.DTD; // setting the type of the scheme (DTD in this case)
v.ValidationEventHandler += new ValidationEventHandler (handle_validation); //new Eventhandler for the validation
while(v.Read());
v.Close();
r.Close();
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.