Esempio n. 1
0
        public XmlSchema Add(string ns, XmlReader reader, System.Xml.XmlResolver resolver)
        {
            SchemaType type;

            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            XmlNameTable nameTable  = reader.NameTable;
            SchemaInfo   schemaInfo = new SchemaInfo();

            System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.None, nameTable, this.GetSchemaNames(nameTable), this.validationEventHandler)
            {
                XmlResolver = resolver
            };
            try
            {
                type = parser.Parse(reader, ns);
            }
            catch (XmlSchemaException exception)
            {
                this.SendValidationEvent(exception);
                return(null);
            }
            if (type == SchemaType.XSD)
            {
                schemaInfo.SchemaType = SchemaType.XSD;
                return(this.Add(ns, schemaInfo, parser.XmlSchema, true, resolver));
            }
            SchemaInfo xdrSchema = parser.XdrSchema;

            return(this.Add(ns, parser.XdrSchema, null, true, resolver));
        }
Esempio n. 2
0
        private void LoadSchemaFromLocation(string uri, string url)
        {
            XmlReader  reader     = null;
            SchemaInfo schemaInfo = null;

            try
            {
                Uri    absoluteUri = base.XmlResolver.ResolveUri(base.BaseUri, url);
                Stream input       = (Stream)base.XmlResolver.GetEntity(absoluteUri, null, null);
                reader = new XmlTextReader(absoluteUri.ToString(), input, base.NameTable);
                System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XSD, base.NameTable, base.SchemaNames, base.EventHandler)
                {
                    XmlResolver = base.XmlResolver
                };
                SchemaType type = parser.Parse(reader, uri);
                schemaInfo = new SchemaInfo {
                    SchemaType = type
                };
                if (type == SchemaType.XSD)
                {
                    if (base.SchemaCollection.EventHandler == null)
                    {
                        base.SchemaCollection.EventHandler = base.EventHandler;
                    }
                    base.SchemaCollection.Add(uri, schemaInfo, parser.XmlSchema, true);
                }
                base.SchemaInfo.Add(schemaInfo, base.EventHandler);
                while (reader.Read())
                {
                }
            }
            catch (XmlSchemaException exception)
            {
                schemaInfo = null;
                base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception.Message }, XmlSeverityType.Error);
            }
            catch (Exception exception2)
            {
                schemaInfo = null;
                base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception2.Message }, XmlSeverityType.Warning);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
 private void LoadSchemaFromLocation(string uri)
 {
     if (XdrBuilder.IsXdrSchema(uri))
     {
         string     relativeUri = uri.Substring("x-schema:".Length);
         XmlReader  reader      = null;
         SchemaInfo sinfo       = null;
         try
         {
             Uri    absoluteUri = base.XmlResolver.ResolveUri(base.BaseUri, relativeUri);
             Stream input       = (Stream)base.XmlResolver.GetEntity(absoluteUri, null, null);
             reader = new XmlTextReader(absoluteUri.ToString(), input, base.NameTable);
             ((XmlTextReader)reader).XmlResolver = base.XmlResolver;
             System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XDR, base.NameTable, base.SchemaNames, base.EventHandler)
             {
                 XmlResolver = base.XmlResolver
             };
             parser.Parse(reader, uri);
             while (reader.Read())
             {
             }
             sinfo = parser.XdrSchema;
         }
         catch (XmlSchemaException exception)
         {
             base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception.Message }, XmlSeverityType.Error);
         }
         catch (Exception exception2)
         {
             base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception2.Message }, XmlSeverityType.Warning);
         }
         finally
         {
             if (reader != null)
             {
                 reader.Close();
             }
         }
         if ((sinfo != null) && (sinfo.ErrorCount == 0))
         {
             base.schemaInfo.Add(sinfo, base.EventHandler);
             base.SchemaCollection.Add(uri, sinfo, null, false);
         }
     }
 }
        public static XmlSchema Read(XmlReader reader, ValidationEventHandler validationEventHandler)
        {
            XmlNameTable nameTable = reader.NameTable;

            System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XSD, nameTable, new SchemaNames(nameTable), validationEventHandler);
            try
            {
                parser.Parse(reader, null);
            }
            catch (XmlSchemaException exception)
            {
                if (validationEventHandler == null)
                {
                    throw exception;
                }
                validationEventHandler(null, new ValidationEventArgs(exception));
                return(null);
            }
            return(parser.XmlSchema);
        }
Esempio n. 5
0
        internal XmlSchema ParseSchema(string targetNamespace, XmlReader reader)
        {
            XmlNameTable nameTable   = reader.NameTable;
            SchemaNames  schemaNames = this.GetSchemaNames(nameTable);

            System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XSD, nameTable, schemaNames, this.eventHandler)
            {
                XmlResolver = this.readerSettings.GetXmlResolver()
            };
            try
            {
                parser.Parse(reader, targetNamespace);
            }
            catch (XmlSchemaException exception)
            {
                this.SendValidationEvent(exception, XmlSeverityType.Error);
                return(null);
            }
            return(parser.XmlSchema);
        }
 private void LoadExternals(XmlSchema schema)
 {
     if (!schema.IsProcessing)
     {
         schema.IsProcessing = true;
         for (int i = 0; i < schema.Includes.Count; i++)
         {
             Uri key = null;
             XmlSchemaExternal source = (XmlSchemaExternal) schema.Includes[i];
             XmlSchema xmlSchema = source.Schema;
             if (xmlSchema != null)
             {
                 key = xmlSchema.BaseUri;
                 if ((key != null) && (this.schemaLocations[key] == null))
                 {
                     this.schemaLocations.Add(key, xmlSchema);
                 }
                 this.LoadExternals(xmlSchema);
             }
             else
             {
                 string schemaLocation = source.SchemaLocation;
                 Uri ruri = null;
                 Exception innerException = null;
                 if (schemaLocation != null)
                 {
                     try
                     {
                         ruri = this.ResolveSchemaLocationUri(schema, schemaLocation);
                     }
                     catch (Exception exception2)
                     {
                         ruri = null;
                         innerException = exception2;
                     }
                 }
                 if (source.Compositor == System.Xml.Schema.Compositor.Import)
                 {
                     XmlSchemaImport import = source as XmlSchemaImport;
                     string item = (import.Namespace != null) ? import.Namespace : string.Empty;
                     if (!schema.ImportedNamespaces.Contains(item))
                     {
                         schema.ImportedNamespaces.Add(item);
                     }
                     if ((item == "http://www.w3.org/XML/1998/namespace") && (ruri == null))
                     {
                         source.Schema = GetBuildInSchema();
                         goto Label_0390;
                     }
                 }
                 if (ruri == null)
                 {
                     if (schemaLocation != null)
                     {
                         base.SendValidationEvent(new XmlSchemaException("Sch_InvalidIncludeLocation", null, innerException, source.SourceUri, source.LineNumber, source.LinePosition, source), XmlSeverityType.Warning);
                     }
                 }
                 else if (this.schemaLocations[ruri] == null)
                 {
                     object schemaEntity = null;
                     try
                     {
                         schemaEntity = this.GetSchemaEntity(ruri);
                     }
                     catch (Exception exception3)
                     {
                         innerException = exception3;
                         schemaEntity = null;
                     }
                     if (schemaEntity != null)
                     {
                         source.BaseUri = ruri;
                         Type c = schemaEntity.GetType();
                         if (typeof(XmlSchema).IsAssignableFrom(c))
                         {
                             source.Schema = (XmlSchema) schemaEntity;
                             this.schemaLocations.Add(ruri, source.Schema);
                             this.LoadExternals(source.Schema);
                             goto Label_0390;
                         }
                         XmlReader reader = null;
                         if (c.IsSubclassOf(typeof(Stream)))
                         {
                             this.readerSettings.CloseInput = true;
                             this.readerSettings.XmlResolver = this.xmlResolver;
                             reader = XmlReader.Create((Stream) schemaEntity, this.readerSettings, ruri.ToString());
                         }
                         else if (c.IsSubclassOf(typeof(XmlReader)))
                         {
                             reader = (XmlReader) schemaEntity;
                         }
                         else if (c.IsSubclassOf(typeof(TextReader)))
                         {
                             this.readerSettings.CloseInput = true;
                             this.readerSettings.XmlResolver = this.xmlResolver;
                             reader = XmlReader.Create((TextReader) schemaEntity, this.readerSettings, ruri.ToString());
                         }
                         if (reader == null)
                         {
                             base.SendValidationEvent("Sch_InvalidIncludeLocation", source, XmlSeverityType.Warning);
                             goto Label_0390;
                         }
                         try
                         {
                             try
                             {
                                 System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XSD, base.NameTable, base.SchemaNames, base.EventHandler);
                                 parser.Parse(reader, null);
                                 while (reader.Read())
                                 {
                                 }
                                 xmlSchema = parser.XmlSchema;
                                 source.Schema = xmlSchema;
                                 this.schemaLocations.Add(ruri, xmlSchema);
                                 this.LoadExternals(xmlSchema);
                             }
                             catch (XmlSchemaException exception4)
                             {
                                 base.SendValidationEvent("Sch_CannotLoadSchemaLocation", schemaLocation, exception4.Message, exception4.SourceUri, exception4.LineNumber, exception4.LinePosition);
                             }
                             catch (Exception exception5)
                             {
                                 base.SendValidationEvent(new XmlSchemaException("Sch_InvalidIncludeLocation", null, exception5, source.SourceUri, source.LineNumber, source.LinePosition, source), XmlSeverityType.Warning);
                             }
                             goto Label_0390;
                         }
                         finally
                         {
                             reader.Close();
                         }
                     }
                     base.SendValidationEvent(new XmlSchemaException("Sch_InvalidIncludeLocation", null, innerException, source.SourceUri, source.LineNumber, source.LinePosition, source), XmlSeverityType.Warning);
                 }
                 else
                 {
                     source.Schema = (XmlSchema) this.schemaLocations[ruri];
                 }
             Label_0390:;
             }
         }
     }
 }
 public static XmlSchema Read(XmlReader reader, ValidationEventHandler validationEventHandler)
 {
     XmlNameTable nameTable = reader.NameTable;
     System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XSD, nameTable, new SchemaNames(nameTable), validationEventHandler);
     try
     {
         parser.Parse(reader, null);
     }
     catch (XmlSchemaException exception)
     {
         if (validationEventHandler == null)
         {
             throw exception;
         }
         validationEventHandler(null, new ValidationEventArgs(exception));
         return null;
     }
     return parser.XmlSchema;
 }
 private bool LoadSchema(string uri)
 {
     if (this.xmlResolver != null)
     {
         uri = this._NameTable.Add(uri);
         if (this._SchemaInfo.TargetNamespaces.ContainsKey(uri))
         {
             return false;
         }
         SchemaInfo sinfo = null;
         Uri baseUri = this.xmlResolver.ResolveUri(null, this._reader.BaseURI);
         XmlReader reader = null;
         try
         {
             Uri absoluteUri = this.xmlResolver.ResolveUri(baseUri, uri.Substring("x-schema:".Length));
             Stream input = (Stream) this.xmlResolver.GetEntity(absoluteUri, null, null);
             reader = new XmlTextReader(absoluteUri.ToString(), input, this._NameTable);
             sinfo = new SchemaInfo();
             System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XDR, this._NameTable, this._SchemaNames, this.validationEventHandler) {
                 XmlResolver = this.xmlResolver
             };
             parser.Parse(reader, uri);
             sinfo = parser.XdrSchema;
         }
         catch (XmlException exception)
         {
             this.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception.Message }, XmlSeverityType.Warning);
             sinfo = null;
         }
         finally
         {
             if (reader != null)
             {
                 reader.Close();
             }
         }
         if ((sinfo != null) && (sinfo.ErrorCount == 0))
         {
             this._SchemaInfo.Add(sinfo, this.validationEventHandler);
             return true;
         }
     }
     return false;
 }
 private void LoadSchemaFromLocation(string uri, string url)
 {
     XmlReader reader = null;
     SchemaInfo schemaInfo = null;
     try
     {
         Uri absoluteUri = base.XmlResolver.ResolveUri(base.BaseUri, url);
         Stream input = (Stream) base.XmlResolver.GetEntity(absoluteUri, null, null);
         reader = new XmlTextReader(absoluteUri.ToString(), input, base.NameTable);
         System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XSD, base.NameTable, base.SchemaNames, base.EventHandler) {
             XmlResolver = base.XmlResolver
         };
         SchemaType type = parser.Parse(reader, uri);
         schemaInfo = new SchemaInfo {
             SchemaType = type
         };
         if (type == SchemaType.XSD)
         {
             if (base.SchemaCollection.EventHandler == null)
             {
                 base.SchemaCollection.EventHandler = base.EventHandler;
             }
             base.SchemaCollection.Add(uri, schemaInfo, parser.XmlSchema, true);
         }
         base.SchemaInfo.Add(schemaInfo, base.EventHandler);
         while (reader.Read())
         {
         }
     }
     catch (XmlSchemaException exception)
     {
         schemaInfo = null;
         base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception.Message }, XmlSeverityType.Error);
     }
     catch (Exception exception2)
     {
         schemaInfo = null;
         base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception2.Message }, XmlSeverityType.Warning);
     }
     finally
     {
         if (reader != null)
         {
             reader.Close();
         }
     }
 }
 private void LoadSchemaFromLocation(string uri)
 {
     if (XdrBuilder.IsXdrSchema(uri))
     {
         string relativeUri = uri.Substring("x-schema:".Length);
         XmlReader reader = null;
         SchemaInfo sinfo = null;
         try
         {
             Uri absoluteUri = base.XmlResolver.ResolveUri(base.BaseUri, relativeUri);
             Stream input = (Stream) base.XmlResolver.GetEntity(absoluteUri, null, null);
             reader = new XmlTextReader(absoluteUri.ToString(), input, base.NameTable);
             ((XmlTextReader) reader).XmlResolver = base.XmlResolver;
             System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XDR, base.NameTable, base.SchemaNames, base.EventHandler) {
                 XmlResolver = base.XmlResolver
             };
             parser.Parse(reader, uri);
             while (reader.Read())
             {
             }
             sinfo = parser.XdrSchema;
         }
         catch (XmlSchemaException exception)
         {
             base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception.Message }, XmlSeverityType.Error);
         }
         catch (Exception exception2)
         {
             base.SendValidationEvent("Sch_CannotLoadSchema", new string[] { uri, exception2.Message }, XmlSeverityType.Warning);
         }
         finally
         {
             if (reader != null)
             {
                 reader.Close();
             }
         }
         if ((sinfo != null) && (sinfo.ErrorCount == 0))
         {
             base.schemaInfo.Add(sinfo, base.EventHandler);
             base.SchemaCollection.Add(uri, sinfo, null, false);
         }
     }
 }
 internal XmlSchema ParseSchema(string targetNamespace, XmlReader reader)
 {
     XmlNameTable nameTable = reader.NameTable;
     SchemaNames schemaNames = this.GetSchemaNames(nameTable);
     System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.XSD, nameTable, schemaNames, this.eventHandler) {
         XmlResolver = this.readerSettings.GetXmlResolver()
     };
     try
     {
         parser.Parse(reader, targetNamespace);
     }
     catch (XmlSchemaException exception)
     {
         this.SendValidationEvent(exception, XmlSeverityType.Error);
         return null;
     }
     return parser.XmlSchema;
 }
 public XmlSchema Add(string ns, XmlReader reader, System.Xml.XmlResolver resolver)
 {
     SchemaType type;
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     XmlNameTable nameTable = reader.NameTable;
     SchemaInfo schemaInfo = new SchemaInfo();
     System.Xml.Schema.Parser parser = new System.Xml.Schema.Parser(SchemaType.None, nameTable, this.GetSchemaNames(nameTable), this.validationEventHandler) {
         XmlResolver = resolver
     };
     try
     {
         type = parser.Parse(reader, ns);
     }
     catch (XmlSchemaException exception)
     {
         this.SendValidationEvent(exception);
         return null;
     }
     if (type == SchemaType.XSD)
     {
         schemaInfo.SchemaType = SchemaType.XSD;
         return this.Add(ns, schemaInfo, parser.XmlSchema, true, resolver);
     }
     SchemaInfo xdrSchema = parser.XdrSchema;
     return this.Add(ns, parser.XdrSchema, null, true, resolver);
 }