Microsoft.Protocols.TestSuites.MS_SITESS.AdapterHelper.MessageValidation C# (CSharp) Méthode

MessageValidation() public static méthode

Validate whether an xml message follows the schema.
public static MessageValidation ( string message, string schema ) : void
message string The xml message.
schema string The schema of the message.
Résultat void
        public static void MessageValidation(string message, string schema)
        {
            validationInfo.Clear();
            XmlReaderSettings schemaSettings = new XmlReaderSettings();
            using (StringReader a = new StringReader(schema))
            {
                schemaSettings.Schemas.Add(null, XmlReader.Create(a));
                schemaSettings.ValidationType = ValidationType.Schema;
                schemaSettings.ConformanceLevel = ConformanceLevel.Document;
                schemaSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
                schemaSettings.ValidationEventHandler += new ValidationEventHandler(Schema_ValidationEventHandler);

                using (StringReader m = new StringReader(message))
                {
                    XmlReader xmlReader = XmlReader.Create(m, schemaSettings);
                    try
                    {
                        while (xmlReader.Read())
                        {
                        }
                    }
                    catch (XmlException)
                    {
                        // The exception will be handled by parent caller.
                        return;
                    }
                }
            }
        }