Esempio n. 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            Validation val = new Validation();
            ErrorsCount ec = new ErrorsCount();
            try
            {
                ec = val.ValidateXmlDocument(xmlPath, xsdPath);
                string msg = ec.validationFlag ? "Walidacja zakończona powodzeniem" : "Walidacja zakończona niepowodzeniem";
                string msg2 = "\n\nLiczba błędów: " + ec.errorsCount.ToString() + "\nLiczba ostrzeżeń: " + ec.warningsCount.ToString();

                MessageBox.Show(msg + msg2, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex){
                if(ex is FileNotFoundException || ex is ArgumentException)
                    MessageBox.Show("Nie załadowano pliku z XML lub XSD!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 2
0
        public ErrorsCount ValidateXmlDocument(string xmlPath, string xsdPath)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(xmlPath);
            doc.Schemas.Add("", xsdPath);
            doc.Schemas.Compile();
            TheSchemaErrors = new List<string>();
            TheSchemaWarnings = new List<string>();
            doc.Validate(Xml_ValidationEventHandler);

            ErrorsCount ec = new ErrorsCount();
            ec.errorsCount = TheSchemaErrors.Count;
            ec.warningsCount = TheSchemaWarnings.Count;
            if (ec.errorsCount > 0)
                ec.validationFlag = false;
            else
                ec.validationFlag = true;

            return ec;
        }