Inheritance: XmlReader, IXmlLineInfo, IXmlNamespaceResolver
Exemplo n.º 1
0
 internal void TrimSpacesInValue()
 {
     if (ValueBuffered)
     {
         XmlTextReaderImpl.StripSpaces(_chars, _valueStartPos, ref _valueLength);
     }
     else
     {
         _value = XmlTextReaderImpl.StripSpaces(_value);
     }
 }
 internal void TrimSpacesInValue()
 {
     if (ValueBuffered)
     {
         Debug.Assert(_chars != null);
         XmlTextReaderImpl.StripSpaces(_chars, _valueStartPos, ref _valueLength);
     }
     else
     {
         Debug.Assert(_value != null);
         _value = XmlTextReaderImpl.StripSpaces(_value);
     }
 }
Exemplo n.º 3
0
#pragma warning disable 618
        // Creates a XmlValidatingReader suitable for parsing InnerXml strings
        private XmlReader CreateInnerXmlReader(String xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc)
        {
            XmlNodeType contentNT = nt;

            if (contentNT == XmlNodeType.Entity || contentNT == XmlNodeType.EntityReference)
            {
                contentNT = XmlNodeType.Element;
            }

            XmlTextReaderImpl tr = new XmlTextReaderImpl(xmlFragment, contentNT, context);

            tr.XmlValidatingReaderCompatibilityMode = true;
            if (doc.HasSetResolver)
            {
                tr.XmlResolver = doc.GetResolver();
            }
            if (!(doc.ActualLoadingStatus))
            {
                tr.DisableUndeclaredEntityCheck = true;
            }
            Debug.Assert(tr.EntityHandling == EntityHandling.ExpandCharEntities);

            XmlDocumentType dtdNode = doc.DocumentType;

            if (dtdNode != null)
            {
                tr.Namespaces = dtdNode.ParseWithNamespaces;
                if (dtdNode.DtdSchemaInfo != null)
                {
                    tr.SetDtdInfo(dtdNode.DtdSchemaInfo);
                }
                else
                {
                    IDtdParser dtdParser = DtdParser.Create();
                    XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(tr);

                    IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, proxy);

                    // TODO: Change all of XmlDocument to IDtdInfo interfaces
                    dtdNode.DtdSchemaInfo = dtdInfo as SchemaInfo;
                    tr.SetDtdInfo(dtdInfo);
                }
            }

            if (nt == XmlNodeType.Entity || nt == XmlNodeType.EntityReference)
            {
                tr.Read(); //this will skip the first element "wrapper"
                tr.ResolveEntity();
            }
            return(tr);
        }
Exemplo n.º 4
0
        private XmlReader CreateInnerXmlReader(string xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc)
        {
            XmlNodeType fragType = nt;

            switch (fragType)
            {
            case XmlNodeType.Entity:
            case XmlNodeType.EntityReference:
                fragType = XmlNodeType.Element;
                break;
            }
            XmlTextReaderImpl reader = new XmlTextReaderImpl(xmlFragment, fragType, context)
            {
                XmlValidatingReaderCompatibilityMode = true
            };

            if (doc.HasSetResolver)
            {
                reader.XmlResolver = doc.GetResolver();
            }
            if (!doc.ActualLoadingStatus)
            {
                reader.DisableUndeclaredEntityCheck = true;
            }
            XmlDocumentType documentType = doc.DocumentType;

            if (documentType != null)
            {
                reader.Namespaces = documentType.ParseWithNamespaces;
                if (documentType.DtdSchemaInfo != null)
                {
                    reader.SetDtdInfo(documentType.DtdSchemaInfo);
                }
                else
                {
                    IDtdParser parser = DtdParser.Create();
                    XmlTextReaderImpl.DtdParserProxy adapter = new XmlTextReaderImpl.DtdParserProxy(reader);
                    IDtdInfo newDtdInfo = parser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, adapter);
                    documentType.DtdSchemaInfo = newDtdInfo as SchemaInfo;
                    reader.SetDtdInfo(newDtdInfo);
                }
            }
            if ((nt == XmlNodeType.Entity) || (nt == XmlNodeType.EntityReference))
            {
                reader.Read();
                reader.ResolveEntity();
            }
            return(reader);
        }
Exemplo n.º 5
0
        // Initializes a new instance of XmlValidatingReaderImpl class with the specified arguments.
        // This constructor is used when creating XmlValidatingReaderImpl reader via "XmlReader.Create(..)"
        internal XmlValidatingReaderImpl(XmlReader reader, ValidationEventHandler?settingsEventHandler, bool processIdentityConstraints)
        {
            XmlAsyncCheckReader?asyncCheckReader = reader as XmlAsyncCheckReader;

            if (asyncCheckReader != null)
            {
                reader = asyncCheckReader.CoreReader;
            }

            _outerReader    = this;
            _coreReader     = reader;
            _coreReaderImpl = (reader as XmlTextReaderImpl) !;
            if (_coreReaderImpl == null)
            {
                XmlTextReader?tr = reader as XmlTextReader;
                if (tr != null)
                {
                    _coreReaderImpl = tr.Impl;
                }
            }

            if (_coreReaderImpl == null)
            {
                throw new ArgumentException(SR.Arg_ExpectingXmlTextReader, nameof(reader));
            }

            _coreReaderImpl.XmlValidatingReaderCompatibilityMode = true;
            _coreReaderNSResolver       = reader as IXmlNamespaceResolver;
            _processIdentityConstraints = processIdentityConstraints;

#pragma warning disable 618

            _schemaCollection = new XmlSchemaCollection(_coreReader.NameTable);

#pragma warning restore 618

            _schemaCollection.XmlResolver = GetResolver();

            _eventHandling = new ValidationEventHandling(this);
            if (settingsEventHandler != null)
            {
                _eventHandling.AddHandler(settingsEventHandler);
            }
            _coreReaderImpl.ValidationEventHandling = _eventHandling;
            _coreReaderImpl.OnDefaultAttributeUse   = new XmlTextReaderImpl.OnDefaultAttributeUseDelegate(ValidateDefaultAttributeOnUse);

            _validationType = ValidationType.DTD;
            SetupValidation(ValidationType.DTD);
        }
Exemplo n.º 6
0
 internal void AdjustLineInfo(int valueOffset, bool isNormalized, ref LineInfo lineInfo)
 {
     if (valueOffset == 0)
     {
         return;
     }
     if (_valueStartPos != -1)
     {
         XmlTextReaderImpl.AdjustLineInfo(_chars, _valueStartPos, _valueStartPos + valueOffset, isNormalized, ref lineInfo);
     }
     else
     {
         XmlTextReaderImpl.AdjustLineInfo(_value, 0, valueOffset, isNormalized, ref lineInfo);
     }
 }
Exemplo n.º 7
0
 internal void AdjustLineInfo(int valueOffset, bool isNormalized, ref LineInfo lineInfo)
 {
     if (valueOffset == 0)
     {
         return;
     }
     if (valueStartPos != -1)
     {
         XmlTextReaderImpl.AdjustLineInfo(chars, valueStartPos, valueStartPos + valueOffset, isNormalized, ref lineInfo);
     }
     else
     {
         char[] chars = value.ToCharArray(0, valueOffset);
         XmlTextReaderImpl.AdjustLineInfo(chars, 0, chars.Length, isNormalized, ref lineInfo);
     }
 }
        // Initializes a new instance of XmlValidatingReaderImpl class with the specified arguments.
        // This constructor is used when creating XmlValidatingReaderImpl reader via "XmlReader.Create(..)"
        internal XmlValidatingReaderImpl(XmlReader reader, ValidationEventHandler settingsEventHandler, bool processIdentityConstraints)
        {
            XmlAsyncCheckReader asyncCheckReader = reader as XmlAsyncCheckReader;

            if (asyncCheckReader != null)
            {
                reader = asyncCheckReader.CoreReader;
            }
            outerReader    = this;
            coreReader     = reader;
            coreReaderImpl = reader as XmlTextReaderImpl;
            if (coreReaderImpl == null)
            {
                XmlTextReader tr = reader as XmlTextReader;
                if (tr != null)
                {
                    coreReaderImpl = tr.Impl;
                }
            }
            if (coreReaderImpl == null)
            {
                throw new ArgumentException(Res.GetString(Res.Arg_ExpectingXmlTextReader), "reader");
            }
            coreReaderImpl.XmlValidatingReaderCompatibilityMode = true;
            coreReaderNSResolver            = reader as IXmlNamespaceResolver;
            this.processIdentityConstraints = processIdentityConstraints;

#pragma warning disable 618

            schemaCollection = new XmlSchemaCollection(coreReader.NameTable);

#pragma warning restore 618

            schemaCollection.XmlResolver = GetResolver();

            eventHandling = new ValidationEventHandling(this);
            if (settingsEventHandler != null)
            {
                eventHandling.AddHandler(settingsEventHandler);
            }
            coreReaderImpl.ValidationEventHandling = eventHandling;
            coreReaderImpl.OnDefaultAttributeUse   = new XmlTextReaderImpl.OnDefaultAttributeUseDelegate(ValidateDefaultAttributeOnUse);

            validationType = ValidationType.DTD;
            SetupValidation(ValidationType.DTD);
        }
 private XmlReader CreateInnerXmlReader(string xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc)
 {
     XmlNodeType fragType = nt;
     switch (fragType)
     {
         case XmlNodeType.Entity:
         case XmlNodeType.EntityReference:
             fragType = XmlNodeType.Element;
             break;
     }
     XmlTextReaderImpl reader = new XmlTextReaderImpl(xmlFragment, fragType, context) {
         XmlValidatingReaderCompatibilityMode = true
     };
     if (doc.HasSetResolver)
     {
         reader.XmlResolver = doc.GetResolver();
     }
     if (!doc.ActualLoadingStatus)
     {
         reader.DisableUndeclaredEntityCheck = true;
     }
     XmlDocumentType documentType = doc.DocumentType;
     if (documentType != null)
     {
         reader.Namespaces = documentType.ParseWithNamespaces;
         if (documentType.DtdSchemaInfo != null)
         {
             reader.SetDtdInfo(documentType.DtdSchemaInfo);
         }
         else
         {
             IDtdParser parser = DtdParser.Create();
             XmlTextReaderImpl.DtdParserProxy adapter = new XmlTextReaderImpl.DtdParserProxy(reader);
             IDtdInfo newDtdInfo = parser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, adapter);
             documentType.DtdSchemaInfo = newDtdInfo as SchemaInfo;
             reader.SetDtdInfo(newDtdInfo);
         }
     }
     if ((nt == XmlNodeType.Entity) || (nt == XmlNodeType.EntityReference))
     {
         reader.Read();
         reader.ResolveEntity();
     }
     return reader;
 }
Exemplo n.º 10
0
        internal XmlReader CreateReader(TextReader input, string baseUriString, XmlParserContext inputContext)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (baseUriString == null)
            {
                baseUriString = string.Empty;
            }
            XmlReader reader = new XmlTextReaderImpl(input, this, baseUriString, inputContext);

            if (this.ValidationType != System.Xml.ValidationType.None)
            {
                reader = this.AddValidation(reader);
            }
            return(reader);
        }
Exemplo n.º 11
0
        // Initializes a new instance of XmlValidatingReaderImpl class with the specified arguments.
        // This constructor is used when creating XmlValidatingReaderImpl reader via "XmlReader.Create(..)"
        internal XmlValidatingReaderImpl(XmlReader reader, ValidationEventHandler settingsEventHandler, bool processIdentityConstraints)
        {
            outerReader    = this;
            coreReader     = reader;
            coreReaderImpl = reader as XmlTextReaderImpl;
            if (coreReaderImpl == null)
            {
                XmlTextReader tr = reader as XmlTextReader;
                if (tr != null)
                {
                    coreReaderImpl = tr.Impl;
                }
            }
            if (coreReaderImpl == null)
            {
                throw new ArgumentException(Res.GetString(Res.Arg_ExpectingXmlTextReader), "reader");
            }
            coreReaderImpl.XmlValidatingReaderCompatibilityMode = true;
            coreReaderNSResolver            = reader as IXmlNamespaceResolver;
            this.processIdentityConstraints = processIdentityConstraints;

#pragma warning disable 618

            schemaCollection = new XmlSchemaCollection(coreReader.NameTable);

#pragma warning restore 618

            schemaCollection.XmlResolver = GetResolver();

            if (settingsEventHandler == null)
            {
                internalEventHandler = new ValidationEventHandler(InternalValidationCallback);
                eventHandler         = internalEventHandler;
                coreReaderImpl.ValidationEventHandler = internalEventHandler;
            }
            else
            {
                eventHandler = settingsEventHandler;
                coreReaderImpl.ValidationEventHandler = settingsEventHandler;
            }

            validationType = ValidationType.DTD;
            SetupValidation(ValidationType.DTD);
        }
Exemplo n.º 12
0
        private void ParseDocumentType(XmlDocumentType dtNode, bool bUseResolver, XmlResolver resolver)
        {
            _doc = dtNode.OwnerDocument;
            XmlParserContext  pc = new XmlParserContext(null, new XmlNamespaceManager(_doc.NameTable), null, null, null, null, _doc.BaseURI, string.Empty, XmlSpace.None);
            XmlTextReaderImpl tr = new XmlTextReaderImpl("", XmlNodeType.Element, pc);

            tr.Namespaces = dtNode.ParseWithNamespaces;
            if (bUseResolver)
            {
                tr.XmlResolver = resolver;
            }

            IDtdParser dtdParser = DtdParser.Create();

            XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(tr);

            IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(_doc.BaseURI, dtNode.Name, dtNode.PublicId, dtNode.SystemId, dtNode.InternalSubset, proxy);

            LoadDocumentType(dtdInfo, dtNode);
        }
Exemplo n.º 13
0
        private void ParseDocumentType(XmlDocumentType dtNode, bool bUseResolver, XmlResolver resolver)
        {
            this.doc = dtNode.OwnerDocument;
            XmlParserContext  context = new XmlParserContext(null, new XmlNamespaceManager(this.doc.NameTable), null, null, null, null, this.doc.BaseURI, string.Empty, XmlSpace.None);
            XmlTextReaderImpl reader  = new XmlTextReaderImpl("", XmlNodeType.Element, context)
            {
                Namespaces = dtNode.ParseWithNamespaces
            };

            if (bUseResolver)
            {
                reader.XmlResolver = resolver;
            }
            IDtdParser parser = DtdParser.Create();

            XmlTextReaderImpl.DtdParserProxy adapter = new XmlTextReaderImpl.DtdParserProxy(reader);
            IDtdInfo dtdInfo = parser.ParseFreeFloatingDtd(this.doc.BaseURI, dtNode.Name, dtNode.PublicId, dtNode.SystemId, dtNode.InternalSubset, adapter);

            this.LoadDocumentType(dtdInfo, dtNode);
        }
        public XmlReader CreateReader(Stream stream, string baseUri) {
            XmlReader reader;
            if (xmlReaderSettings != null) {
                reader = XmlTextReader.Create(stream, xmlReaderSettings, baseUri);
            } else {
                XmlTextReaderImpl readerImpl = new XmlTextReaderImpl(baseUri, stream, xmlNameTable);
                readerImpl.EntityHandling = entityHandling;
                readerImpl.Namespaces = namespaces;
                readerImpl.Normalization = normalization;
                readerImpl.DtdProcessing = prohibitDtd ? DtdProcessing.Prohibit : DtdProcessing.Parse;
                readerImpl.WhitespaceHandling = whitespaceHandling;
                readerImpl.XmlResolver = xmlResolver;
                reader = readerImpl;
            }
            if (validatingReader) {
#pragma warning disable 618
                reader = new XmlValidatingReader(reader);
#pragma warning restore 618
            }
            return reader;
        }
Exemplo n.º 15
0
        //
        // Constructors
        //
        // Initializes a new instance of XmlValidatingReaderImpl class with the specified XmlReader.
        // This constructor is used when creating XmlValidatingReaderImpl for V1 XmlValidatingReader
        internal XmlValidatingReaderImpl(XmlReader reader)
        {
            XmlAsyncCheckReader asyncCheckReader = reader as XmlAsyncCheckReader;

            if (asyncCheckReader != null)
            {
                reader = asyncCheckReader.CoreReader;
            }
            _outerReader          = this;
            _coreReader           = reader;
            _coreReaderNSResolver = reader as IXmlNamespaceResolver;
            _coreReaderImpl       = reader as XmlTextReaderImpl;
            if (_coreReaderImpl == null)
            {
                XmlTextReader tr = reader as XmlTextReader;
                if (tr != null)
                {
                    _coreReaderImpl = tr.Impl;
                }
            }
            if (_coreReaderImpl == null)
            {
                throw new ArgumentException(SR.Arg_ExpectingXmlTextReader, "reader");
            }
            _coreReaderImpl.EntityHandling = EntityHandling.ExpandEntities;
            _coreReaderImpl.XmlValidatingReaderCompatibilityMode = true;
            _processIdentityConstraints = true;

#pragma warning disable 618
            _schemaCollection             = new XmlSchemaCollection(_coreReader.NameTable);
            _schemaCollection.XmlResolver = GetResolver();

            _eventHandling = new ValidationEventHandling(this);
            _coreReaderImpl.ValidationEventHandling = _eventHandling;
            _coreReaderImpl.OnDefaultAttributeUse   = new XmlTextReaderImpl.OnDefaultAttributeUseDelegate(ValidateDefaultAttributeOnUse);

            _validationType = ValidationType.Auto;
            SetupValidation(ValidationType.Auto);
#pragma warning restore 618
        }
Exemplo n.º 16
0
        internal XmlReader CreateReader(TextReader input, string baseUriString, XmlParserContext inputContext)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (baseUriString == null)
            {
                baseUriString = string.Empty;
            }

            // create xml text reader
            XmlReader reader = new XmlTextReaderImpl(input, this, baseUriString, inputContext);


            if (_useAsync)
            {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }

            return(reader);
        }
Exemplo n.º 17
0
        internal XmlReader CreateReader(Stream input, Uri baseUri, string baseUriString, XmlParserContext inputContext)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }
            if (baseUriString == null)
            {
                if (baseUri == null)
                {
                    baseUriString = string.Empty;
                }
                else
                {
                    baseUriString = baseUri.ToString();
                }
            }

            // create text XML reader
            XmlReader reader = new XmlTextReaderImpl(input, null, 0, this, baseUri, baseUriString, inputContext, closeInput);

#if !SILVERLIGHT
            // wrap with validating reader
            if (this.ValidationType != ValidationType.None)
            {
                reader = AddValidation(reader);
            }
#endif

#if ASYNC
            if (useAsync)
            {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }
#endif

            return(reader);
        }
Exemplo n.º 18
0
        internal XmlReader CreateReader(String inputUri, XmlParserContext inputContext)
        {
            if (inputUri == null)
            {
                throw new ArgumentNullException("inputUri");
            }
            if (inputUri.Length == 0)
            {
                throw new ArgumentException(Res.GetString(Res.XmlConvert_BadUri), "inputUri");
            }

            // resolve and open the url
            XmlResolver tmpResolver = this.GetXmlResolver();

            if (tmpResolver == null)
            {
                tmpResolver = CreateDefaultResolver();
            }

            // create text XML reader
            XmlReader reader = new XmlTextReaderImpl(inputUri, this, inputContext, tmpResolver);

#if !SILVERLIGHT
            // wrap with validating reader
            if (this.ValidationType != ValidationType.None)
            {
                reader = AddValidation(reader);
            }
#endif

#if ASYNC
            if (useAsync)
            {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }
#endif
            return(reader);
        }
Exemplo n.º 19
0
 public XmlTextReader(string url)
 {
     _impl             = new XmlTextReaderImpl(url, new NameTable());
     _impl.OuterReader = this;
 }
Exemplo n.º 20
0
 public XmlTextReader(string url, TextReader input, XmlNameTable nt)
 {
     _impl             = new XmlTextReaderImpl(url, input, nt);
     _impl.OuterReader = this;
 }
Exemplo n.º 21
0
 public XmlTextReader(TextReader input)
 {
     _impl             = new XmlTextReaderImpl(input);
     _impl.OuterReader = this;
 }
 private XmlTextReaderImpl SetupReader(XmlTextReaderImpl reader)
 {
     reader.EntityHandling = EntityHandling.ExpandEntities;
     reader.XmlValidatingReaderCompatibilityMode = true;
     return reader;
 }
Exemplo n.º 23
0
        private static XmlReader CreateReaderImpl(Stream input, XmlReaderSettings settings, Uri baseUri, string baseUriStr,
                                                   XmlParserContext inputContext, bool closeInput) {
            if (input == null) {
                throw new ArgumentNullException("input");
            }
            if (baseUriStr == null) {
                Debug.Assert(baseUri == null);
                baseUriStr = string.Empty;
            }

            // create text XML reader
            XmlReader reader = new XmlTextReaderImpl(input, null, 0, settings, baseUri, baseUriStr, inputContext, closeInput);

            // wrap with validating reader
            if ( settings.ValidationType != ValidationType.None ) {
                reader = AddValidation(reader, settings);
            }
            return reader;
        }
Exemplo n.º 24
0
 public XmlTextReader(Stream input, XmlNameTable nt)
 {
     _impl = new XmlTextReaderImpl(input, nt);
     _impl.OuterReader = this;
 }
        internal void ValidateDefaultAttributeOnUse(IDtdDefaultAttributeInfo defaultAttribute, XmlTextReaderImpl coreReader)
        {
            SchemaAttDef attdef = defaultAttribute as SchemaAttDef;

            if (attdef == null)
            {
                return;
            }

            if (!attdef.DefaultValueChecked)
            {
                SchemaInfo schemaInfo = coreReader.DtdInfo as SchemaInfo;
                if (schemaInfo == null)
                {
                    return;
                }
                DtdValidator.CheckDefaultValue(attdef, schemaInfo, eventHandling, coreReader.BaseURI);
            }
        }
Exemplo n.º 26
0
 public XmlTextReader(Stream input)
 {
     _impl = new XmlTextReaderImpl(input);
     _impl.OuterReader = this;
 }
Exemplo n.º 27
0
 public XmlTextReader(string url, Stream input)
 {
     _impl = new XmlTextReaderImpl(url, input);
     _impl.OuterReader = this;
 }
Exemplo n.º 28
0
 public XmlTextReader(Stream xmlFragment, XmlNodeType fragType, XmlParserContext context)
 {
     impl             = new XmlTextReaderImpl(xmlFragment, fragType, context);
     impl.OuterReader = this;
 }
Exemplo n.º 29
0
//
// Internal static Parse method
//
        static internal SchemaInfo Parse( XmlNameTable nt, XmlNamespaceManager nsManager, bool namespaces, string baseUri, string docTypeName, 
                                          string publicId, string systemId, string internalSubset, bool useResolver, XmlResolver resolver ) {

            XmlParserContext pc = new XmlParserContext( nt, nsManager, null, null, null, null, baseUri, string.Empty, XmlSpace.None );
            XmlTextReaderImpl tr = new XmlTextReaderImpl( "", XmlNodeType.Element, pc );
            tr.Namespaces = namespaces;
            if ( useResolver ) {
                tr.XmlResolver = resolver;
            }

            return DtdParser.Parse( tr, baseUri, docTypeName, publicId, systemId, internalSubset ); 
        }
        //
        // Constructors
        //
        // Initializes a new instance of XmlValidatingReaderImpl class with the specified XmlReader.
        // This constructor is used when creating XmlValidatingReaderImpl for V1 XmlValidatingReader
        internal XmlValidatingReaderImpl(XmlReader reader)
        {
            XmlAsyncCheckReader asyncCheckReader = reader as XmlAsyncCheckReader;
            if (asyncCheckReader != null)
            {
                reader = asyncCheckReader.CoreReader;
            }
            _outerReader = this;
            _coreReader = reader;
            _coreReaderNSResolver = reader as IXmlNamespaceResolver;
            _coreReaderImpl = reader as XmlTextReaderImpl;
            if (_coreReaderImpl == null)
            {
                XmlTextReader tr = reader as XmlTextReader;
                if (tr != null)
                {
                    _coreReaderImpl = tr.Impl;
                }
            }
            if (_coreReaderImpl == null)
            {
                throw new ArgumentException(SR.Arg_ExpectingXmlTextReader, nameof(reader));
            }
            _coreReaderImpl.EntityHandling = EntityHandling.ExpandEntities;
            _coreReaderImpl.XmlValidatingReaderCompatibilityMode = true;
            _processIdentityConstraints = true;

#pragma warning disable 618
            _schemaCollection = new XmlSchemaCollection(_coreReader.NameTable);
            _schemaCollection.XmlResolver = GetResolver();

            _eventHandling = new ValidationEventHandling(this);
            _coreReaderImpl.ValidationEventHandling = _eventHandling;
            _coreReaderImpl.OnDefaultAttributeUse = new XmlTextReaderImpl.OnDefaultAttributeUseDelegate(ValidateDefaultAttributeOnUse);

            _validationType = ValidationType.Auto;
            SetupValidation(ValidationType.Auto);
#pragma warning restore 618

        }
Exemplo n.º 31
0
        internal XmlReader CreateReader(TextReader input, string baseUriString, XmlParserContext inputContext)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }
            if (baseUriString == null)
            {
                baseUriString = string.Empty;
            }

            // create xml text reader
            XmlReader reader = new XmlTextReaderImpl(input, this, baseUriString, inputContext);

            // wrap with validating reader
            if (this.ValidationType != ValidationType.None)
            {
                reader = AddValidation(reader);
            }

            if (_useAsync)
            {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }

            return reader;
        }
Exemplo n.º 32
0
 public XmlTextReader(Stream xmlFragment, XmlNodeType fragType, XmlParserContext context)
 {
     _impl = new XmlTextReaderImpl(xmlFragment, fragType, context);
     _impl.OuterReader = this;
 }
Exemplo n.º 33
0
        internal NavigatorInput ResolveDocument(Uri absoluteUri)
        {
            Debug.Assert(_xmlResolver != null);
            object input = _xmlResolver.GetEntity(absoluteUri, null, null);
            string resolved = absoluteUri.ToString();

            if (input is Stream)
            {
                XmlTextReaderImpl tr = new XmlTextReaderImpl(resolved, (Stream)input);
                {
                    tr.XmlResolver = _xmlResolver;
                }
                // reader is closed by Compiler.LoadDocument()
                return new NavigatorInput(Compiler.LoadDocument(tr).CreateNavigator(), resolved, _rootScope);
            }
            else if (input is XPathNavigator)
            {
                return new NavigatorInput((XPathNavigator)input, resolved, _rootScope);
            }
            else
            {
                throw XsltException.Create(SR.Xslt_CantResolve, resolved);
            }
        }
        // Initializes a new instance of XmlValidatingReaderImpl class with the specified arguments.
        // This constructor is used when creating XmlValidatingReaderImpl reader via "XmlReader.Create(..)"
        internal XmlValidatingReaderImpl( XmlReader reader, ValidationEventHandler settingsEventHandler, bool processIdentityConstraints) {
            XmlAsyncCheckReader asyncCheckReader = reader as XmlAsyncCheckReader;
            if (asyncCheckReader != null) {
                reader = asyncCheckReader.CoreReader;
            }
            outerReader = this;
            coreReader = reader;
            coreReaderImpl = reader as XmlTextReaderImpl;
            if ( coreReaderImpl == null ) {
                XmlTextReader tr = reader as XmlTextReader;
                if ( tr != null ) {
                    coreReaderImpl = tr.Impl;
                }
            }
            if ( coreReaderImpl == null ) {
                throw new ArgumentException( Res.GetString( Res.Arg_ExpectingXmlTextReader ), "reader" );
            }
            coreReaderImpl.XmlValidatingReaderCompatibilityMode = true;
            coreReaderNSResolver = reader as IXmlNamespaceResolver;
            this.processIdentityConstraints = processIdentityConstraints;

#pragma warning disable 618

            schemaCollection = new XmlSchemaCollection( coreReader.NameTable );

#pragma warning restore 618

            schemaCollection.XmlResolver = GetResolver();
            
            eventHandling = new ValidationEventHandling(this);
            if (settingsEventHandler != null) {
                eventHandling.AddHandler(settingsEventHandler);
            }
            coreReaderImpl.ValidationEventHandling = eventHandling;
            coreReaderImpl.OnDefaultAttributeUse = new XmlTextReaderImpl.OnDefaultAttributeUseDelegate(ValidateDefaultAttributeOnUse);

            validationType = ValidationType.DTD;
            SetupValidation( ValidationType.DTD );
        }
Exemplo n.º 35
0
        // !!!!!!
        // NOTE: This method is called via reflection from System.Data.dll and from Analysis Services in Yukon. 
        // Do not change its signature without notifying the appropriate teams!
        // !!!!!!
        internal static XmlReader CreateSqlReader(Stream input, XmlReaderSettings settings, XmlParserContext inputContext) {
            if (input == null) {
                throw new ArgumentNullException("input");
            }
            if (settings == null) {
                settings = new XmlReaderSettings();
            }

            XmlReader reader;

            // allocate byte buffer
            byte[] bytes = new byte[CalcBufferSize(input)];

#if false
            {
                // catch the binary XML input and dump it into a local file (for debugging and testing purposes)

                // create dump file name
                string dumpFileNameBase = "~CreateSqlReaderInputDump";
                string dumpFileName;
                int i = 0;
                do {
                    i++;
                    dumpFileName = Path.GetFullPath(string.Concat(dumpFileNameBase, i.ToString(), ".bmx"));
                } while (File.Exists(dumpFileName));

                // dump the input into the file
                FileStream fs = new FileStream(dumpFileName, FileMode.Create, FileAccess.ReadWrite);
                byte[] buffer = new byte[4096];
                int bytesRead;
                while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0) {
                    fs.Write(buffer, 0, bytesRead);
                }
                fs.Seek(0, SeekOrigin.Begin);

                // make sure it will get closed
                if (settings.CloseInput) {
                    input.Close();
                }
                input = fs;
                settings = settings.Clone();
                settings.CloseInput = true;
            }
#endif
            int byteCount = 0;
            int read;
            do {
                read = input.Read(bytes, byteCount, bytes.Length - byteCount);
                byteCount += read;
            } while (read > 0 && byteCount < 2);

            // create text or binary XML reader depenting on the stream first 2 bytes
            if (byteCount >= 2 && (bytes[0] == 0xdf && bytes[1] == 0xff)) {
                if ( inputContext != null )
                    throw new ArgumentException(Res.GetString(Res.XmlBinary_NoParserContext), "inputContext");
                reader = new XmlSqlBinaryReader(input, bytes, byteCount, string.Empty, settings.CloseInput, settings);
            }
            else {
                reader = new XmlTextReaderImpl(input, bytes, byteCount, settings, null, string.Empty, inputContext, settings.CloseInput);
            }
            
            // wrap with validating reader
            if ( settings.ValidationType != ValidationType.None ) {
                reader = settings.AddValidation( reader );
            }

            if (settings.Async) {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }

            return reader;
        }
Exemplo n.º 36
0
 public XmlTextReader(Stream input)
 {
     impl             = new XmlTextReaderImpl(input);
     impl.OuterReader = this;
 }
Exemplo n.º 37
0
 public XmlTextReader( string url ) {
     impl = new XmlTextReaderImpl( url, new NameTable() );
     impl.OuterReader = this;
 }
Exemplo n.º 38
0
 protected XmlTextReader(XmlNameTable nt)
 {
     _impl             = new XmlTextReaderImpl(nt);
     _impl.OuterReader = this;
 }
Exemplo n.º 39
0
        internal XmlReader CreateReader(Stream input, Uri baseUri, string baseUriString, XmlParserContext inputContext) {
            if (input == null) {
                throw new ArgumentNullException("input");
            }
            if (baseUriString == null) {
                if (baseUri == null) {
                    baseUriString = string.Empty;
                }
                else {
                    baseUriString = baseUri.ToString();
                }
            }

            // create text XML reader
            XmlReader reader = new XmlTextReaderImpl(input, null, 0, this, baseUri, baseUriString, inputContext, closeInput);

#if !SILVERLIGHT
            // wrap with validating reader
            if (this.ValidationType != ValidationType.None) {
                reader = AddValidation(reader);
            }
#endif

#if ASYNC
            if (useAsync) {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }
#endif

            return reader;
        }
Exemplo n.º 40
0
 static internal SchemaInfo Parse( XmlTextReaderImpl tr, string baseUri, string docTypeName, string publicId, string systemId, string internalSubset ) {
     XmlTextReaderImpl.DtdParserProxy dtdParserProxy = new XmlTextReaderImpl.DtdParserProxy( baseUri, docTypeName, publicId, systemId, internalSubset, tr ); 
     dtdParserProxy.Parse( false );
     return dtdParserProxy.DtdSchemaInfo;
 }
        internal void ValidateDefaultAttributeOnUse(IDtdDefaultAttributeInfo defaultAttribute, XmlTextReaderImpl coreReader) {
            SchemaAttDef attdef = defaultAttribute as SchemaAttDef;
            if (attdef == null) {
                return;
            }

            if (!attdef.DefaultValueChecked) {
                SchemaInfo schemaInfo = coreReader.DtdInfo as SchemaInfo;
                if (schemaInfo == null) {
                    return;
                }
                DtdValidator.CheckDefaultValue(attdef, schemaInfo, eventHandling, coreReader.BaseURI);
            }
        }
 internal DtdParserProxy(XmlTextReaderImpl reader)
 {
     _reader = reader;
 }
Exemplo n.º 43
0
 protected XmlTextReader()
 {
     _impl             = new XmlTextReaderImpl();
     _impl.OuterReader = this;
 }
Exemplo n.º 44
0
 public XmlTextReader(string url, TextReader input)
 {
     impl             = new XmlTextReaderImpl(url, input);
     impl.OuterReader = this;
 }
Exemplo n.º 45
0
 public XmlTextReader(string url, Stream input)
 {
     _impl             = new XmlTextReaderImpl(url, input);
     _impl.OuterReader = this;
 }
Exemplo n.º 46
0
 public XmlTextReader( String url, XmlNameTable nt ) {
     impl = new XmlTextReaderImpl( url, nt );
     impl.OuterReader = this;
 }
Exemplo n.º 47
0
 public XmlTextReader(TextReader input, XmlNameTable nt)
 {
     _impl             = new XmlTextReaderImpl(input, nt);
     _impl.OuterReader = this;
 }
Exemplo n.º 48
0
 public XmlTextReader(Stream input, XmlNameTable nt)
 {
     impl             = new XmlTextReaderImpl(input, nt);
     impl.OuterReader = this;
 }
Exemplo n.º 49
0
 public XmlTextReader(string xmlFragment, XmlNodeType fragType, XmlParserContext context)
 {
     _impl             = new XmlTextReaderImpl(xmlFragment, fragType, context);
     _impl.OuterReader = this;
 }
Exemplo n.º 50
0
 protected XmlTextReader( XmlNameTable nt ) {
     impl = new XmlTextReaderImpl( nt );
     impl.OuterReader = this;
 }
Exemplo n.º 51
0
        internal XmlReader CreateReader(String inputUri, XmlParserContext inputContext)
        {
            if (inputUri == null)
            {
                throw new ArgumentNullException(nameof(inputUri));
            }
            if (inputUri.Length == 0)
            {
                throw new ArgumentException(SR.XmlConvert_BadUri, nameof(inputUri));
            }

            // resolve and open the url
            XmlResolver tmpResolver = this.GetXmlResolver();
            if (tmpResolver == null)
            {
                tmpResolver = CreateDefaultResolver();
            }

            // create text XML reader
            XmlReader reader = new XmlTextReaderImpl(inputUri, this, inputContext, tmpResolver);

            // wrap with validating reader
            if (this.ValidationType != ValidationType.None)
            {
                reader = AddValidation(reader);
            }

            if (_useAsync)
            {
                reader = XmlAsyncCheckReader.CreateAsyncCheckWrapper(reader);
            }

            return reader;
        }
Exemplo n.º 52
0
 public XmlTextReader( TextReader input ) {
     impl = new XmlTextReaderImpl( input );
     impl.OuterReader = this;
 }
Exemplo n.º 53
0
        //
        // Input documents management
        //

        internal static XPathDocument LoadDocument(XmlTextReaderImpl reader)
        {
            reader.EntityHandling = EntityHandling.ExpandEntities;
            reader.XmlValidatingReaderCompatibilityMode = true;
            try
            {
                return new XPathDocument(reader, XmlSpace.Preserve);
            }
            finally
            {
                reader.Close();
            }
        }
Exemplo n.º 54
0
 public XmlTextReader( string url, TextReader input ) { 
     impl = new XmlTextReaderImpl( url, input );
     impl.OuterReader = this;
 }
 internal static XmlReader CreateSqlReader(Stream input, XmlReaderSettings settings, XmlParserContext inputContext)
 {
     XmlReader reader;
     int num2;
     if (input == null)
     {
         throw new ArgumentNullException("input");
     }
     if (settings == null)
     {
         settings = new XmlReaderSettings();
     }
     byte[] buffer = new byte[CalcBufferSize(input)];
     int offset = 0;
     do
     {
         num2 = input.Read(buffer, offset, buffer.Length - offset);
         offset += num2;
     }
     while ((num2 > 0) && (offset < 2));
     if (((offset >= 2) && (buffer[0] == 0xdf)) && (buffer[1] == 0xff))
     {
         if (inputContext != null)
         {
             throw new ArgumentException(Res.GetString("XmlBinary_NoParserContext"), "inputContext");
         }
         reader = new XmlSqlBinaryReader(input, buffer, offset, string.Empty, settings.CloseInput, settings);
     }
     else
     {
         reader = new XmlTextReaderImpl(input, buffer, offset, settings, null, string.Empty, inputContext, settings.CloseInput);
     }
     if (settings.ValidationType != ValidationType.None)
     {
         reader = settings.AddValidation(reader);
     }
     return reader;
 }
Exemplo n.º 56
0
 public XmlTextReader( TextReader input, XmlNameTable nt ) {
     impl = new XmlTextReaderImpl( input, nt );
     impl.OuterReader = this;
 }
Exemplo n.º 57
0
 public XmlTextReader( string url, TextReader input, XmlNameTable nt ) {
     impl = new XmlTextReaderImpl( url, input, nt );
     impl.OuterReader = this;
 }
Exemplo n.º 58
0
 public XmlTextReader( string xmlFragment, XmlNodeType fragType, XmlParserContext context ) {
     impl = new XmlTextReaderImpl( xmlFragment, fragType, context );
     impl.OuterReader = this;
 }
Exemplo n.º 59
0
//
//
// Constructors
//
        protected XmlTextReader() {
            impl = new XmlTextReaderImpl();
            impl.OuterReader = this;
        }
Exemplo n.º 60
0
        private static XmlReader CreateReaderImpl(TextReader input, XmlReaderSettings settings, string baseUriStr,
                                                   XmlParserContext context) {
            if (input == null) {
                throw new ArgumentNullException("input");
            }
            if (settings == null) {
                settings = new XmlReaderSettings();
            }
            if (baseUriStr == null) {
                baseUriStr = string.Empty;
            }

            // create xml text reader
            XmlReader reader = new XmlTextReaderImpl(input, settings, baseUriStr, context);

            // wrap with validating reader
            if (settings.ValidationType == ValidationType.Schema) {
                reader = new XsdValidatingReader(reader, settings.GetXmlResolver(), settings);
            }
            else if (settings.ValidationType == ValidationType.DTD) {
                reader = CreateDtdValidatingReader(reader, settings);
            }
            return reader;
        }