Example #1
0
        internal XmlReader CreateReader(string inputUri, XmlParserContext inputContext)
        {
            XmlReader reader;

            if (inputUri == null)
            {
                throw new ArgumentNullException("inputUri");
            }
            if (inputUri.Length == 0)
            {
                throw new ArgumentException(Res.GetString("XmlConvert_BadUri"), "inputUri");
            }
            System.Xml.XmlResolver xmlResolver = this.GetXmlResolver();
            if (xmlResolver == null)
            {
                xmlResolver = this.CreateDefaultResolver();
            }
            Uri    absoluteUri = xmlResolver.ResolveUri(null, inputUri);
            Stream input       = (Stream)xmlResolver.GetEntity(absoluteUri, string.Empty, typeof(Stream));

            if (input == null)
            {
                throw new XmlException("Xml_CannotResolveUrl", inputUri);
            }
            XmlReaderSettings settings = this;

            if (!settings.CloseInput)
            {
                settings            = settings.Clone();
                settings.CloseInput = true;
            }
            try
            {
                reader = settings.CreateReader(input, absoluteUri, null, inputContext);
            }
            catch
            {
                input.Close();
                throw;
            }
            return(reader);
        }
Example #2
0
 private void SetupValidation(System.Xml.ValidationType valType)
 {
     this.validator = BaseValidator.CreateInstance(valType, this, this.schemaCollection, this.eventHandling, this.processIdentityConstraints);
     System.Xml.XmlResolver resolver = this.GetResolver();
     this.validator.XmlResolver = resolver;
     if (this.outerReader.BaseURI.Length > 0)
     {
         this.validator.BaseUri = (resolver == null) ? new Uri(this.outerReader.BaseURI, UriKind.RelativeOrAbsolute) : resolver.ResolveUri(null, this.outerReader.BaseURI);
     }
     this.coreReaderImpl.ValidationEventHandling = (this.validationType == System.Xml.ValidationType.None) ? null : this.eventHandling;
 }