Example #1
0
        public void ValidateContext(XmlCache xcache)
        {
            this._cache = xcache;
            if (string.IsNullOrEmpty(_cache.FileName))
            {
                _baseUri = null;
            }
            else
            {
                _baseUri = new Uri(new Uri(xcache.FileName), new Uri(".", UriKind.Relative));
            }

            SchemaResolver resolver = xcache.SchemaResolver as SchemaResolver;

            resolver.Handler = OnValidationEvent;
            XmlDocument doc = xcache.Document;

            this._info       = new XmlSchemaInfo();
            this._nsResolver = new MyXmlNamespaceResolver(doc.NameTable);
            XmlSchemaSet set = new XmlSchemaSet();
            // Make sure the SchemaCache is up to date with document.
            SchemaCache sc = xcache.SchemaCache;

            foreach (XmlSchema s in doc.Schemas.Schemas())
            {
                sc.Add(s);
            }

            if (LoadSchemas(doc, set, resolver))
            {
                set.ValidationEventHandler += OnValidationEvent;
                set.Compile();
                set.ValidationEventHandler -= OnValidationEvent;
            }

            this._validator = new XmlSchemaValidator(doc.NameTable, set, _nsResolver,
                                                     XmlSchemaValidationFlags.AllowXmlAttributes |
                                                     XmlSchemaValidationFlags.ProcessIdentityConstraints |
                                                     XmlSchemaValidationFlags.ProcessInlineSchema);

            this._validator.ValidationEventHandler += OnValidationEvent;
            this._validator.XmlResolver             = resolver;
            this._validator.Initialize();

            this._nsResolver.Context = doc;
            ValidateContent(doc);
            this._nsResolver.Context = doc;

            this._validator.EndValidation();
        }
Example #2
0
        public void ValidateContext(XmlCache xcache)
        {
            this.cache = xcache;
            if (string.IsNullOrEmpty(cache.FileName)) {
                baseUri = null;
            } else {
                baseUri = new Uri(new Uri(xcache.FileName), new Uri(".", UriKind.Relative));
            }
            ValidationEventHandler handler = new ValidationEventHandler(OnValidationEvent);
            SchemaResolver resolver = xcache.SchemaResolver as SchemaResolver;
            resolver.Handler = handler;
            XmlDocument doc = xcache.Document;
            this.info = new XmlSchemaInfo();
            this.nsResolver = new MyXmlNamespaceResolver(doc.NameTable);
            XmlSchemaSet set = new XmlSchemaSet();
            // Make sure the SchemaCache is up to date with document.
            SchemaCache sc = xcache.SchemaCache;
            foreach (XmlSchema s in doc.Schemas.Schemas()) {
                sc.Add(s);
            }

            if (LoadSchemas(doc, set, resolver)) {
                set.ValidationEventHandler += handler;
                set.Compile();
            }

            this.validator = new XmlSchemaValidator(doc.NameTable, set, nsResolver,
                XmlSchemaValidationFlags.AllowXmlAttributes |
                XmlSchemaValidationFlags.ProcessIdentityConstraints |
                XmlSchemaValidationFlags.ProcessInlineSchema);

            this.validator.ValidationEventHandler += handler;
            this.validator.XmlResolver = resolver;
            this.validator.Initialize();

            this.nsResolver.Context = doc;
            ValidateContent(doc);
            this.nsResolver.Context = doc;

            this.validator.EndValidation();
        }
Example #3
0
        public void ValidateContext(XmlCache xcache)
        {
            this.cache = xcache;
            if (string.IsNullOrEmpty(cache.FileName)) {
                baseUri = null;
            } else {
                baseUri = new Uri(new Uri(xcache.FileName), new Uri(".", UriKind.Relative));
            }
            ValidationEventHandler handler = new ValidationEventHandler(OnValidationEvent);
            SchemaResolver resolver = xcache.SchemaResolver as SchemaResolver;
            resolver.Handler = handler;
            XmlDocument doc = xcache.Document;
            this.info = new XmlSchemaInfo();
            this.nsResolver = new MyXmlNamespaceResolver(doc.NameTable);
            XmlSchemaSet set = new XmlSchemaSet();
            // Make sure the SchemaCache is up to date with document.
            SchemaCache sc = xcache.SchemaCache;
            foreach (XmlSchema s in doc.Schemas.Schemas()) {
                sc.Add(s);
            }

            // hack to force application to validate with local copy of collada schema
            try
            {
                string appPath = Directory.GetCurrentDirectory();
                set.Add("http://www.w3.org/XML/1998/namespace", appPath + "/xml.xsd");
                set.Add("http://www.collada.org/2005/11/COLLADASchema", appPath + "/collada_schema_1_4.xsd");
            } catch
            {
                Console.WriteLine("Cannot find xml.xmd or collada_schema_1_4.xsd" );
            }

            if (LoadSchemas(doc, set, resolver)) {
                set.ValidationEventHandler += handler;
                set.Compile();
            }

            this.validator = new XmlSchemaValidator(doc.NameTable, set, nsResolver,
                XmlSchemaValidationFlags.AllowXmlAttributes |
                XmlSchemaValidationFlags.ProcessIdentityConstraints |
                XmlSchemaValidationFlags.ProcessInlineSchema);

            this.validator.ValidationEventHandler += handler;
            this.validator.XmlResolver = resolver;
            this.validator.Initialize();

            this.nsResolver.Context = doc;
            ValidateContent(doc);
            this.nsResolver.Context = doc;

            this.validator.EndValidation();
        }