Exemplo n.º 1
0
        public void Validate(string xmlPath, ValidationErrorDelegate validationErrorDelegate)
        {
            XmlUrlResolver xmlResolver = new XmlUrlResolver();

            xmlResolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

            XmlReaderSettings rs = new XmlReaderSettings();

            rs.ValidationType               = ValidationType.Schema;
            rs.IgnoreComments               = true;
            rs.IgnoreWhitespace             = true;
            rs.IgnoreProcessingInstructions = true;
            rs.XmlResolver = xmlResolver;

            List <string> errors = new List <string>();

            _groupedErrors = null;

            using (XmlTextReader textReader = new XmlTextReader(xmlPath))
            {
                rs.ValidationEventHandler +=
                    delegate(object sender, ValidationEventArgs args)
                {
                    AppendError(textReader, args, validationErrorDelegate);
                };
                using (XmlReader reader = XmlReader.Create(textReader, rs))
                {
                    while (reader.Read()) /*Empty loop*/ } {
            }
        }
        OutputGroupedErrors(validationErrorDelegate);
    }
Exemplo n.º 2
0
    public void Validate(Stream xmlStream, Stream xsdStream, ValidationErrorDelegate validationErrorDelegate)
    {
        _groupedErrors = null;
        XmlSchema schema = new XmlSchema();

        using (StreamReader schemaReader = new StreamReader(xsdStream))
        {
            schema = XmlSchema.Read(schemaReader,
                                    delegate(object sender, ValidationEventArgs args)
                {
                    AppendError(args, validationErrorDelegate);
                });
        }

        XmlReaderSettings readerSettings = new XmlReaderSettings();

        readerSettings.ValidationType = ValidationType.Schema;
        readerSettings.Schemas.Add(schema);

        using (XmlTextReader textReader = new XmlTextReader(xmlStream))
        {
            readerSettings.ValidationEventHandler +=
                delegate(object sender, ValidationEventArgs args)
            {
                AppendError(textReader, args, validationErrorDelegate);
            };
            using (XmlReader reader = XmlReader.Create(textReader, readerSettings))
            {
                while (reader.Read()) /*Empty loop*/ } {
        }
    }
    OutputGroupedErrors(validationErrorDelegate);
}
Exemplo n.º 3
0
 public ValueCollection(LinkedDictionary <TKey, TValue> dictionary)
 {
     if (dictionary == null)
     {
         throw new ArgumentNullException("dictionary");
     }
     _dictionary = dictionary;
 }
Exemplo n.º 4
0
private void AppendGroupedError(string message)
{
    if (_groupedErrors == null)
    {
        _groupedErrors = new LinkedDictionary <string, int>();
    }
    if (_groupedErrors.ContainsKey(message))
    {
        int currentCount = _groupedErrors[message];
        _groupedErrors[message] = currentCount + 1;
    }
    else
    {
        _groupedErrors[message] = 1;
    }
}