Exemple #1
0
        // [ResourceConsumption(ResourceScope.Machine)]
        // [ResourceExposure(ResourceScope.Machine)]
        private void LoadSchema(string uri, string url)
        {
            if (this.XmlResolver == null)
            {
                return;
            }
            if (SchemaInfo.TargetNamespaces.ContainsKey(uri) && _nsManager.LookupPrefix(uri) != null)
            {
                return;
            }

            SchemaInfo schemaInfo = null;

            if (SchemaCollection != null)
            {
                schemaInfo = SchemaCollection.GetSchemaInfo(uri);
            }
            if (schemaInfo != null)
            {
                if (schemaInfo.SchemaType != SchemaType.XSD)
                {
                    throw new XmlException(ResXml.Xml_MultipleValidaitonTypes, string.Empty, this.PositionInfo.LineNumber, this.PositionInfo.LinePosition);
                }
                SchemaInfo.Add(schemaInfo, EventHandler);
                return;
            }
            if (url != null)
            {
                LoadSchemaFromLocation(uri, url);
            }
        }
Exemple #2
0
 private void ProcessInlineSchema()
 {
     if (!_inlineSchemaParser.ParseReaderNode())
     { // Done
         _inlineSchemaParser.FinishParsing();
         XmlSchema schema   = _inlineSchemaParser.XmlSchema;
         string    inlineNS = null;
         if (schema != null && schema.ErrorCount == 0)
         {
             try
             {
                 SchemaInfo inlineSchemaInfo = new SchemaInfo();
                 inlineSchemaInfo.SchemaType = SchemaType.XSD;
                 inlineNS = schema.TargetNamespace == null ? string.Empty : schema.TargetNamespace;
                 if (!SchemaInfo.TargetNamespaces.ContainsKey(inlineNS))
                 {
                     if (SchemaCollection.Add(inlineNS, inlineSchemaInfo, schema, true) != null)
                     { //If no errors on compile
                         //Add to validator's SchemaInfo
                         SchemaInfo.Add(inlineSchemaInfo, EventHandler);
                     }
                 }
             }
             catch (XmlSchemaException e)
             {
                 SendValidationEvent(ResXml.Sch_CannotLoadSchema, new string[] { BaseUri.AbsoluteUri, e.Message }, XmlSeverityType.Error);
             }
         }
         _inlineSchemaParser = null;
     }
 }
Exemple #3
0
        // [ResourceConsumption(ResourceScope.Machine)]
        // [ResourceExposure(ResourceScope.Machine)]
        private void LoadSchemaFromLocation(string uri, string url)
        {
            XmlReader  reader     = null;
            SchemaInfo schemaInfo = null;

            try
            {
                Uri    ruri = this.XmlResolver.ResolveUri(BaseUri, url);
                Stream stm  = (Stream)this.XmlResolver.GetEntity(ruri, null, null);
                reader = new XmlTextReader(ruri.ToString(), stm, NameTable);
                //XmlSchema schema = SchemaCollection.Add(uri, reader, this.XmlResolver);

                Parser parser = new Parser(SchemaType.XSD, NameTable, SchemaNames, EventHandler);
                parser.XmlResolver = this.XmlResolver;
                SchemaType schemaType = parser.Parse(reader, uri);

                schemaInfo            = new SchemaInfo();
                schemaInfo.SchemaType = schemaType;
                if (schemaType == SchemaType.XSD)
                {
                    if (SchemaCollection.EventHandler == null)
                    {
                        SchemaCollection.EventHandler = this.EventHandler;
                    }
                    SchemaCollection.Add(uri, schemaInfo, parser.XmlSchema, true);
                }
                //Add to validator's SchemaInfo
                SchemaInfo.Add(schemaInfo, EventHandler);

                while (reader.Read())
                {
                    ;                  // wellformness check
                }
            }
            catch (XmlSchemaException e)
            {
                schemaInfo = null;
                SendValidationEvent(ResXml.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Error);
            }
            catch (Exception e)
            {
                schemaInfo = null;
                SendValidationEvent(ResXml.Sch_CannotLoadSchema, new string[] { uri, e.Message }, XmlSeverityType.Warning);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }