public static void validatexml(String str) { XmlValidatingReader validate= null; //URL of path containing XML data XmlTextReader xRead = new XmlTextReader(str); //Load selected document validate = new XmlValidatingReader(xRead); //Validate xmlreader validate.ValidationType = ValidationType.Schema; //Validate Schema of loaded xml file validate.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack); try { while (validate.Read()) { } if (m_valid) { MessageBox.Show("Valid documnent"); m_valid = true; } } catch { MessageBox.Show("Incorrect file or XML document not well formed"); } validate.Close(); } public static void ValidationCallBack(object sender,ValidationEventArgs args) { MessageBox.Show("Validation error :" + args.Message); m_valid = false; }