Exemplo n.º 1
0
        bool LoadSchemas(XmlDocument doc, XmlSchemaSet set, SchemaResolver resolver)
        {
            XmlElement root = doc.DocumentElement;

            if (root == null)
            {
                return(false);
            }
            // Give Xsi schemas highest priority.
            bool result = LoadXsiSchemas(doc, set, resolver);

            SchemaCache sc = this.cache.SchemaCache;

            foreach (XmlAttribute a in root.Attributes)
            {
                if (a.NamespaceURI == "http://www.w3.org/2000/xmlns/")
                {
                    string nsuri = a.Value;
                    result |= LoadSchemasForNamespace(set, resolver, sc, nsuri, a);
                }
            }
            if (string.IsNullOrEmpty(root.NamespaceURI))
            {
                result |= LoadSchemasForNamespace(set, resolver, sc, "", root);
            }
            return(result);
        }
Exemplo n.º 2
0
        void LoadSchemas()
        {
            if (this.cache == null)
            {
                if (this.Site != null)
                {
                    this.cache = (SchemaCache)this.Site.GetService(typeof(SchemaCache));
                }
            }
            items.Clear();
            DataGridViewRowCollection col = this.dataGridView1.Rows;

            col.Clear();
            if (this.cache != null)
            {
                foreach (CacheEntry e in this.cache.GetSchemas())
                {
                    Uri        uri      = e.Location;
                    string     filename = uri.IsFile ? uri.LocalPath : uri.AbsoluteUri;
                    SchemaItem item     = new SchemaItem(e.Disabled, e.TargetNamespace, filename);
                    items.Add(item);
                    int i = col.Add(item.Values);
                    col[i].Tag = item;
                }
            }
        }
Exemplo n.º 3
0
 public XmlCache(IServiceProvider site, SchemaCache schemaCache, DelayedActions handler)
 {
     this._loader      = new DomLoader(site);
     this._schemaCache = schemaCache;
     this._site        = site;
     this.Document     = new XmlDocument();
     this._actions     = handler;
     this._settings    = (Settings)this._site.GetService(typeof(Settings));
 }
 public XmlCache(IServiceProvider site, ISynchronizeInvoke sync)
 {
     this.loader         = new DomLoader(site);
     this.schemaCache    = new SchemaCache(site);
     this.site           = site;
     this.sync           = sync;
     this.Document       = new XmlDocument();
     this.timer.Tick    += new EventHandler(Reload);
     this.timer.Interval = 1000;
     this.timer.Enabled  = false;
 }
Exemplo n.º 5
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();
        }
 public virtual IIntellisenseList GetExpectedNames()
 {
     if (checker != null)
     {
         XmlIntellisenseList list = new XmlIntellisenseList();
         if (node.NodeType == XmlNodeType.Attribute)
         {
             XmlSchemaAttribute[] expected = checker.GetExpectedAttributes();
             if (expected != null)
             {
                 foreach (XmlSchemaAttribute a in expected)
                 {
                     list.Add(GetQualifiedName(a), SchemaCache.GetAnnotation(a, SchemaCache.AnnotationNode.Tooltip, null));
                 }
             }
         }
         else
         {
             XmlSchemaParticle[] particles = checker.GetExpectedParticles();
             if (particles != null)
             {
                 foreach (XmlSchemaParticle p in particles)
                 {
                     if (p is XmlSchemaElement)
                     {
                         list.Add(GetQualifiedName((XmlSchemaElement)p), SchemaCache.GetAnnotation(p, SchemaCache.AnnotationNode.Tooltip, null));
                     }
                     else
                     {
                         // todo: expand XmlSchemaAny particles.
                         list.IsOpen = true;
                     }
                 }
             }
         }
         list.Sort();
         return(list);
     }
     return(null);
 }
Exemplo n.º 7
0
 private bool LoadSchemasForNamespace(XmlSchemaSet set, SchemaResolver resolver, SchemaCache sc, string nsuri, XmlNode ctx)
 {
     bool result = false;
     if (set.Schemas(nsuri).Count == 0) {
         CacheEntry ce = sc.FindSchemasByNamespace(nsuri);
         while (ce != null) {
             if (!ce.Disabled){
                 if (!ce.HasUpToDateSchema) {
                     // delay loaded!
                     LoadSchema(set, resolver, ctx, nsuri, ce.Location.AbsoluteUri);
                 } else {
                     set.Add(ce.Schema);
                 }
                 result = true;
             }
             ce = ce.Next;
         }
     }
     return result;
 }
Exemplo n.º 8
0
 public XmlCache(IServiceProvider site, ISynchronizeInvoke sync)
 {
     this.loader = new DomLoader(site);
     this.schemaCache = new SchemaCache(site);
     this.site = site;
     this.sync = sync;
     this.Document = new XmlDocument();
     this.timer.Tick += new EventHandler(Reload);
     this.timer.Interval = 1000;
     this.timer.Enabled = false;
 }
Exemplo n.º 9
0
 void LoadSchemas()
 {
     if (this.cache == null) {
         if (this.Site != null) {
             this.cache = (SchemaCache)this.Site.GetService(typeof(SchemaCache));
         }
     }
     items.Clear();
     DataGridViewRowCollection col = this.dataGridView1.Rows;
     col.Clear();
     if (this.cache != null) {
         foreach (CacheEntry e in this.cache.GetSchemas()) {
             Uri uri = e.Location;
             string filename = uri.IsFile ? uri.LocalPath : uri.AbsoluteUri;
             SchemaItem item = new SchemaItem(e.Disabled, e.TargetNamespace, filename);
             items.Add(item);
             int i = col.Add(item.Values);
             col[i].Tag = item;
         }
     }
 }
Exemplo n.º 10
0
 public SchemaResolver(SchemaCache cache, IServiceProvider site)
     : base(site)
 {
     this.cache = cache;
 }
Exemplo n.º 11
0
        private bool LoadSchemasForNamespace(XmlSchemaSet set, SchemaResolver resolver, SchemaCache sc, string nsuri, XmlNode ctx)
        {
            bool result = false;

            if (set.Schemas(nsuri).Count == 0)
            {
                CacheEntry ce = sc.FindSchemasByNamespace(nsuri);
                while (ce != null)
                {
                    if (!ce.Disabled)
                    {
                        if (!ce.HasUpToDateSchema)
                        {
                            // delay loaded!
                            LoadSchema(set, resolver, ctx, nsuri, ce.Location.AbsoluteUri);
                        }
                        else
                        {
                            set.Add(ce.Schema);
                        }
                        result = true;
                    }
                    ce = ce.Next;
                }
            }
            return(result);
        }
Exemplo n.º 12
0
 public SchemaResolver(SchemaCache cache, IServiceProvider site) : base(site)
 {
     this.cache = cache;
 }
Exemplo n.º 13
0
 public SchemaResolver(SchemaCache cache)
 {
     this.cache = cache;
 }
Exemplo n.º 14
0
 public SchemaResolver(SchemaCache cache, IServiceProvider site)
 {
     this.site  = site;
     this.cache = cache;
 }