BimlGen.BimlGenerator.IsValidBiml C# (CSharp) Метод

IsValidBiml() публичный статический Метод

public static IsValidBiml ( string xml ) : bool
xml string
Результат bool
        public static bool IsValidBiml( string xml )
        {
            // Set validation rules
            var settings = new XmlReaderSettings
                {
                    CloseInput = true,
                    ValidationType = ValidationType.Schema,
                    ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings |
                                      XmlSchemaValidationFlags.ProcessIdentityConstraints |
                                      XmlSchemaValidationFlags.ProcessInlineSchema |
                                      XmlSchemaValidationFlags.ProcessSchemaLocation
                };

            // Get xsd as embedded resource
            Assembly myAssembly = Assembly.GetExecutingAssembly();
            using (Stream schemaStream = myAssembly.GetManifestResourceStream( "BimlGen.Resources.Biml.xsd" ))
            {
                if (schemaStream != null)
                {
                    using (XmlReader schemaReader = XmlReader.Create( schemaStream ))
                    {
                        settings.Schemas.Add( null, schemaReader );
                    }
                }
            }

            // Read through document to validate
            bool isValid = true;
            var stringReader = new StringReader( xml );
            using (XmlReader validatingReader = XmlReader.Create( stringReader, settings ))
            {
                try
                {
                    while (validatingReader.Read()) {}
                }
                catch
                {
                    isValid = false;
                }
            }
            return isValid;
        }