예제 #1
0
        public void ValidateSchema()
        {
            if (SchemaList == null || !SchemaList.Any())
            {
                return;
            }

            var settings = new XmlReaderSettings();

            settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
            settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
            settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;


            SchemaList.ForEach(
                s => settings.Schemas.Add(s.TargetNamespace, XmlReader.Create(new StringReader(s.SchemaContent))));

            settings.ValidationType          = ValidationType.Schema;
            settings.ValidationEventHandler += settings_ValidationEventHandler;
            var reader = XmlReader.Create(new StringReader(XmlToValidate), settings);

            while (reader.Read())
            {
            }
            if (string.IsNullOrEmpty(ErrorXml))
            {
                IsValid = true;
            }
            var errorBuilder = new StringBuilder();

            if (_errors.Any())
            {
                errorBuilder.Append("<errors>");
                _errors.ForEach(e => errorBuilder.AppendFormat("<Error>{0}</Error>", e));
                errorBuilder.Append("</errors>");
                ErrorXml = FdrCommon.FormatXml(errorBuilder.ToString());
            }

            IsValid = !_errors.Any();
        }