Example #1
0
 // Adds the schemas to the schema manager.
 void AddUserSchemas()
 {
     while (widget.AddedSchemas.Count > 0)
     {
         XmlSchemaManager.AddUserSchema(widget.AddedSchemas[0]);
         widget.AddedSchemas.RemoveAt(0);
     }
 }
Example #2
0
 // Removes the schemas from the schema manager.
 void RemoveUserSchemas()
 {
     while (widget.RemovedSchemas.Count > 0)
     {
         XmlSchemaManager.RemoveUserSchema(widget.RemovedSchemas [0].NamespaceUri);
         widget.RemovedSchemas.RemoveAt(0);
     }
 }
Example #3
0
        /// <summary>
        /// Checks whether the element belongs to the XSD namespace.
        /// </summary>
        static bool IsXmlSchemaNamespace(XmlSchemaElement element)
        {
            XmlQualifiedName qualifiedName = element.QualifiedName;

            if (qualifiedName != null)
            {
                return(XmlSchemaManager.IsXmlSchemaNamespace(qualifiedName.Namespace));
            }
            return(false);
        }
Example #4
0
        void SetDefaultSchema()
        {
            var filename = document.FileName;

            if (filename == null)
            {
                return;
            }

            defaultSchemaCompletionData = XmlSchemaManager.GetSchemaCompletionDataForFileName(filename);
            if (defaultSchemaCompletionData != null)
            {
                inferredCompletionData = null;
            }
            else
            {
                QueueInference();
            }
            defaultNamespacePrefix = XmlSchemaManager.GetNamespacePrefixForFileName(filename);
        }
Example #5
0
        /// <summary>
        /// Validates the schema.
        /// </summary>
        public static async Task <List <BuildError> > ValidateSchema(string xml, string filename, CancellationToken token)
        {
            var errors   = new List <BuildError> ();
            var settings = new XmlReaderSettings {
                XmlResolver = new LocalOnlyXmlResolver()
            };

            void validationCallback(object _, ValidationEventArgs args)
            {
                errors.Add(CreateBuildError(args, filename));
            }

            try {
                XmlSchema schema;
                using (var xmlReader = XmlReader.Create(new StringReader(xml))) {
                    schema = XmlSchema.Read(xmlReader, validationCallback);
                }

                var sset = new XmlSchemaSet();
                sset.ValidationEventHandler += validationCallback;

                foreach (XmlSchema s in (await XmlSchemaManager.GetSchemaSet(token)).Schemas())
                {
                    if (s.TargetNamespace != schema.TargetNamespace)
                    {
                        sset.Add(schema);
                    }
                }
                sset.Compile();
            }
            catch (XmlSchemaException ex) {
                errors.Add(CreateBuildError(ex, filename));
            }
            catch (XmlException ex) {
                errors.Add(CreateBuildError(ex, filename));
            }

            return(errors);
        }
Example #6
0
        /// <summary>
        /// Validates the xml against known schemas.
        /// </summary>
        public static async Task <List <BuildError> > ValidateXml(string xml, string filename, CancellationToken token)
        {
            var errors   = new List <BuildError> ();
            var settings = CreateValidationSettings(errors, filename);

            try {
                settings.Schemas = await XmlSchemaManager.GetSchemaSet(token);

                using (var reader = XmlReader.Create(new StringReader(xml), settings)) {
                    while (!reader.EOF)
                    {
                        reader.Read();
                    }
                }
            } catch (XmlSchemaException ex) {
                errors.Add(CreateBuildError(ex, filename));
            }
            catch (XmlException ex) {
                errors.Add(CreateBuildError(ex, filename));
            }

            return(errors);
        }