Example #1
0
        public static XmlReaderSettings CreateSettings(bool ignoreWhitespace, bool ignoreComments, bool checkCharacters, bool ignoreProcessingInstructions,
                                                       ConformanceLevel level, DtdProcessing dtdProcessing, XmlUrlResolver resolver, XmlSchemaValidationFlags validationFlags, ValidationType validationType,
                                                       XmlSchemaSet schemaSet, ValidationEventHandler onErrorHandler)
        {
            XmlReaderSettings settings = new XmlReaderSettings
            {
                CloseInput                   = true,
                IgnoreComments               = ignoreComments,
                IgnoreWhitespace             = ignoreWhitespace,
                CheckCharacters              = checkCharacters,
                IgnoreProcessingInstructions = ignoreProcessingInstructions,
                DtdProcessing                = dtdProcessing,
                ConformanceLevel             = level,
                ValidationFlags              = validationFlags,
                ValidationType               = validationType,
                Schemas     = schemaSet,
                XmlResolver = resolver ?? XmlUrlResolverHelper.CreateResolver()
            };

            if (onErrorHandler != null)
            {
                settings.ValidationEventHandler += onErrorHandler;
            }
            return(settings);
        }
Example #2
0
        private void Initialize(XmlResolver resolver)
        {
            _nameTable   = null;
            _xmlResolver = resolver;
            // limit the entity resolving to 10 million character. the caller can still
            // override it to any other value or set it to zero for unlimiting it
            _maxCharactersFromEntities = (long)1e7;

            _lineNumberOffset   = 0;
            _linePositionOffset = 0;
            _checkCharacters    = true;
            _conformanceLevel   = ConformanceLevel.Document;

            _ignoreWhitespace = false;
            _ignorePIs        = false;
            _ignoreComments   = false;
            _dtdProcessing    = DtdProcessing.Prohibit;
            _closeInput       = false;

            _maxCharactersInDocument = 0;

            _schemas          = null;
            _validationType   = ValidationType.None;
            _validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            _validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;

            _useAsync = false;

            _isReadOnly      = false;
            IsXmlResolverSet = false;
        }
        void Initialize(XmlResolver resolver)
        {
            nameTable          = null;
            xmlResolver        = (resolver == null ? CreateDefaultResolver() : resolver);
            lineNumberOffset   = 0;
            linePositionOffset = 0;
            checkCharacters    = true;
            conformanceLevel   = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs        = false;
            ignoreComments   = false;
            dtdProcessing    = DtdProcessing.Prohibit;
            closeInput       = false;

            maxCharactersFromEntities = 0;
            maxCharactersInDocument   = 0;

#if !SILVERLIGHT
            schemas          = null;
            validationType   = ValidationType.None;
            validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
Example #4
0
        public void XmlReader_DtdProcessingAsParameter(DtdProcessing processing)
        {
            var settings = new XmlReaderSettings
            {
                DtdProcessing = processing,
                XmlResolver   = new XmlUrlResolver()
            };

            XmlReader.Create("uri", settings).Dispose(); // Compliant - we don't track DtdProcessing change between methods
        }
Example #5
0
        private void InitSettings(ValidationType type, DtdProcessing dtdProcessing)
        {
            XmlReaderSettings settings = new XmlReaderSettings
            {
                ValidationType   = type,
                DtdProcessing    = dtdProcessing,
                IgnoreWhitespace = true
            };

            _settings = settings;
        }
 internal XmlCharCheckingReader(XmlReader reader, bool checkCharacters, bool ignoreWhitespace, bool ignoreComments, bool ignorePis, DtdProcessing dtdProcessing) : base(reader)
 {
     this.state = State.Initial;
     this.checkCharacters = checkCharacters;
     this.ignoreWhitespace = ignoreWhitespace;
     this.ignoreComments = ignoreComments;
     this.ignorePis = ignorePis;
     this.dtdProcessing = dtdProcessing;
     this.lastNodeType = XmlNodeType.None;
     if (checkCharacters)
     {
         this.xmlCharType = XmlCharType.Instance;
     }
 }
Example #7
0
 internal XmlCharCheckingReader(XmlReader reader, bool checkCharacters, bool ignoreWhitespace, bool ignoreComments, bool ignorePis, DtdProcessing dtdProcessing) : base(reader)
 {
     this.state            = State.Initial;
     this.checkCharacters  = checkCharacters;
     this.ignoreWhitespace = ignoreWhitespace;
     this.ignoreComments   = ignoreComments;
     this.ignorePis        = ignorePis;
     this.dtdProcessing    = dtdProcessing;
     this.lastNodeType     = XmlNodeType.None;
     if (checkCharacters)
     {
         this.xmlCharType = XmlCharType.Instance;
     }
 }
Example #8
0
        //
        // Constructor
        //
        internal XmlCharCheckingReader(XmlReader reader, bool checkCharacters, bool ignoreWhitespace, bool ignoreComments, bool ignorePis, DtdProcessing dtdProcessing)
            : base(reader)
        {
            Debug.Assert(checkCharacters || ignoreWhitespace || ignoreComments || ignorePis || (int)dtdProcessing != -1);

            _state = State.Initial;

            _checkCharacters  = checkCharacters;
            _ignoreWhitespace = ignoreWhitespace;
            _ignoreComments   = ignoreComments;
            _ignorePis        = ignorePis;
            _dtdProcessing    = dtdProcessing;

            _lastNodeType = XmlNodeType.None;
        }
Example #9
0
        void Initialize(XmlResolver resolver)
        {
            nameTable = null;
#if !SILVERLIGHT
            if (!EnableLegacyXmlSettings())
            {
                xmlResolver = resolver;
                // limit the entity resolving to 10 million character. the caller can still
                // override it to any other value or set it to zero for unlimiting it
                maxCharactersFromEntities = (long)1e7;
            }
            else
#endif
            {
                xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
                maxCharactersFromEntities = 0;
            }
            lineNumberOffset   = 0;
            linePositionOffset = 0;
            checkCharacters    = true;
            conformanceLevel   = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs        = false;
            ignoreComments   = false;
            dtdProcessing    = DtdProcessing.Prohibit;
            closeInput       = false;

            maxCharactersInDocument = 0;

#if !SILVERLIGHT
            schemas          = null;
            validationType   = ValidationType.None;
            validationFlags  = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
//
// Constructor
//
        internal XmlCharCheckingReader( XmlReader reader, bool checkCharacters, bool ignoreWhitespace, bool ignoreComments, bool ignorePis, DtdProcessing dtdProcessing ) 
            : base( reader ) {

            Debug.Assert( checkCharacters || ignoreWhitespace || ignoreComments || ignorePis || (int)dtdProcessing != -1 );

            state = State.Initial;

            this.checkCharacters = checkCharacters;
            this.ignoreWhitespace = ignoreWhitespace;
            this.ignoreComments = ignoreComments;
            this.ignorePis = ignorePis;
            this.dtdProcessing = dtdProcessing;

            lastNodeType = XmlNodeType.None;

            if ( checkCharacters ) {
                xmlCharType = XmlCharType.Instance;
            }
        }
Example #11
0
 private XDocument TryParseXml(string xml, string baseUri, DtdProcessing dtdProcessingMode)
 {
     try
     {
         XmlReaderSettings settings = new XmlReaderSettings
         {
             DtdProcessing = dtdProcessingMode,
             XmlResolver   = new FileXmlUrlResolver()
         };
         using (var stringReader = new StringReader(xml))
             using (var xmlReader = XmlReader.Create(stringReader, settings, baseUri))
             {
                 return(XDocument.Load(xmlReader, LoadOptions.SetLineInfo));
             }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
         return(null);
     }
 }
Example #12
0
        //
        // Private methods
        //
        private void Initialize()
        {
            _nameTable          = null;
            _lineNumberOffset   = 0;
            _linePositionOffset = 0;
            _checkCharacters    = true;
            _conformanceLevel   = ConformanceLevel.Document;

            _ignoreWhitespace = false;
            _ignorePIs        = false;
            _ignoreComments   = false;
            _dtdProcessing    = DtdProcessing.Prohibit;
            _closeInput       = false;

            _maxCharactersFromEntities = 0;
            _maxCharactersInDocument   = 0;


            _useAsync = false;

            _isReadOnly = false;
        }
Example #13
0
 public XmlSchema Add(string targetNamespace, XmlReader schemaDocument)
 {
     if (schemaDocument == null)
     {
         throw new ArgumentNullException("schemaDocument");
     }
     if (targetNamespace != null)
     {
         targetNamespace = XmlComplianceUtil.CDataNormalize(targetNamespace);
     }
     lock (this.InternalSyncObject)
     {
         XmlSchema schema    = null;
         Uri       schemaUri = new Uri(schemaDocument.BaseURI, UriKind.RelativeOrAbsolute);
         if (!this.IsSchemaLoaded(schemaUri, targetNamespace, out schema))
         {
             DtdProcessing dtdProcessing = this.readerSettings.DtdProcessing;
             this.SetDtdProcessing(schemaDocument);
             schema = this.Add(targetNamespace, this.ParseSchema(targetNamespace, schemaDocument));
             this.readerSettings.DtdProcessing = dtdProcessing;
         }
         return(schema);
     }
 }
Example #14
0
        private void Initialize(XmlResolver resolver)
        {
            _nameTable = null;
            if (!EnableLegacyXmlSettings())
            {
                _xmlResolver = resolver;
                // limit the entity resolving to 10 million character. the caller can still
                // override it to any other value or set it to zero for unlimiting it
                _maxCharactersFromEntities = (long)1e7;
            }
            else
            {
                _xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
                _maxCharactersFromEntities = 0;
            }
            _lineNumberOffset = 0;
            _linePositionOffset = 0;
            _checkCharacters = true;
            _conformanceLevel = ConformanceLevel.Document;

            _ignoreWhitespace = false;
            _ignorePIs = false;
            _ignoreComments = false;
            _dtdProcessing = DtdProcessing.Prohibit;
            _closeInput = false;

            _maxCharactersInDocument = 0;

            _schemas = null;
            _validationType = ValidationType.None;
            _validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            _validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;

            _useAsync = false;

            _isReadOnly = false;
            IsXmlResolverSet = false;
        }
 internal XmlCharCheckingReaderWithNS(XmlReader reader, IXmlNamespaceResolver readerAsNSResolver, bool checkCharacters, bool ignoreWhitespace, bool ignoreComments, bool ignorePis, DtdProcessing dtdProcessing)
     : base(reader, checkCharacters, ignoreWhitespace, ignoreComments, ignorePis, dtdProcessing)
 {
     Debug.Assert(readerAsNSResolver != null);
     this.readerAsNSResolver = readerAsNSResolver;
 }
Example #16
0
 internal XmlCharCheckingReaderWithNS(XmlReader reader, IXmlNamespaceResolver readerAsNSResolver, bool checkCharacters, bool ignoreWhitespace, bool ignoreComments, bool ignorePis, DtdProcessing dtdProcessing)
     : base(reader, checkCharacters, ignoreWhitespace, ignoreComments, ignorePis, dtdProcessing)
 {
     Debug.Assert(readerAsNSResolver != null);
     this.readerAsNSResolver = readerAsNSResolver;
 }
Example #17
0
        // This constructor is used when creating XmlTextReaderImpl reader via "XmlReader.Create(..)"
        private XmlTextReaderImpl(XmlResolver resolver, XmlReaderSettings settings, XmlParserContext context)
        {
            _useAsync = settings.Async;
            _v1Compat = false;
            _outerReader = this;

            _xmlContext = new XmlContext();

            // create or get nametable and namespace manager from XmlParserContext
            XmlNameTable nt = settings.NameTable;
            if (context == null)
            {
                if (nt == null)
                {
                    nt = new NameTable();
                    Debug.Assert(_nameTableFromSettings == false);
                }
                else
                {
                    _nameTableFromSettings = true;
                }
                _nameTable = nt;
                _namespaceManager = new XmlNamespaceManager(nt);
            }
            else
            {
                SetupFromParserContext(context, settings);
                nt = _nameTable;
            }

            nt.Add(string.Empty);
            _xml = nt.Add("xml");
            _xmlNs = nt.Add("xmlns");

            _xmlResolver = resolver;

            Debug.Assert(_index == 0);

            _nodes = new NodeData[NodesInitialSize];
            _nodes[0] = new NodeData();
            _curNode = _nodes[0];

            _stringBuilder = new StringBuilder();

            // Needed only for XmlTextReader (reporting of entities)
            _entityHandling = EntityHandling.ExpandEntities;

            _xmlResolverIsSet = settings.IsXmlResolverSet;

            _whitespaceHandling = (settings.IgnoreWhitespace) ? WhitespaceHandling.Significant : WhitespaceHandling.All;
            _normalize = true;
            _ignorePIs = settings.IgnoreProcessingInstructions;
            _ignoreComments = settings.IgnoreComments;
            _checkCharacters = settings.CheckCharacters;
            _lineNumberOffset = settings.LineNumberOffset;
            _linePositionOffset = settings.LinePositionOffset;
            _ps.lineNo = _lineNumberOffset + 1;
            _ps.lineStartPos = -_linePositionOffset - 1;
            _curNode.SetLineInfo(_ps.LineNo - 1, _ps.LinePos - 1);
            _dtdProcessing = settings.DtdProcessing;
            _maxCharactersInDocument = settings.MaxCharactersInDocument;
            _maxCharactersFromEntities = settings.MaxCharactersFromEntities;

            _charactersInDocument = 0;
            _charactersFromEntities = 0;

            _fragmentParserContext = context;

            _parsingFunction = ParsingFunction.SwitchToInteractiveXmlDecl;
            _nextParsingFunction = ParsingFunction.DocumentContent;

            switch (settings.ConformanceLevel)
            {
                case ConformanceLevel.Auto:
                    _fragmentType = XmlNodeType.None;
                    _fragment = true;
                    break;
                case ConformanceLevel.Fragment:
                    _fragmentType = XmlNodeType.Element;
                    _fragment = true;
                    break;
                case ConformanceLevel.Document:
                    _fragmentType = XmlNodeType.Document;
                    break;
                default:
                    Debug.Assert(false);
                    goto case ConformanceLevel.Document;
            }
        }
Example #18
0
        void Initialize(XmlResolver resolver) {
            nameTable = null;
#if !SILVERLIGHT
            if (!EnableLegacyXmlSettings())
            {
                xmlResolver = resolver;
                // limit the entity resolving to 10 million character. the caller can still
                // override it to any other value or set it to zero for unlimiting it
                maxCharactersFromEntities = (long) 1e7;
            }
            else
#endif            
            {
                xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
                maxCharactersFromEntities = 0;
            }
            lineNumberOffset = 0;
            linePositionOffset = 0;
            checkCharacters = true;
            conformanceLevel = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs = false;
            ignoreComments = false;
            dtdProcessing = DtdProcessing.Prohibit;
            closeInput = false;

            maxCharactersInDocument = 0;

#if !SILVERLIGHT
            schemas = null;
            validationType = ValidationType.None;
            validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
        public XmlSqlBinaryReader(System.IO.Stream stream, byte[] data, int len, string baseUri, bool closeInput, XmlReaderSettings settings) {
            unicode = System.Text.Encoding.Unicode;
            xmlCharType = XmlCharType.Instance;

            this.xnt = settings.NameTable;
            if (this.xnt == null) {
                this.xnt = new NameTable();
                this.xntFromSettings = false;
            }
            else {
                this.xntFromSettings = true;
            }
            this.xml = this.xnt.Add("xml");
            this.xmlns = this.xnt.Add("xmlns");
            this.nsxmlns = this.xnt.Add(XmlReservedNs.NsXmlNs);
            this.baseUri = baseUri;
            this.state = ScanState.Init;
            this.nodetype = XmlNodeType.None;
            this.token = BinXmlToken.Error;
            this.elementStack = new ElemInfo[16];
            //this.elemDepth = 0;
            this.attributes = new AttrInfo[8];
            this.attrHashTbl = new int[8];
            //this.attrCount = 0;
            //this.attrIndex = 0;
            this.symbolTables.Init();
            this.qnameOther.Clear();
            this.qnameElement.Clear();
            this.xmlspacePreserve = false;
            this.hasher = new SecureStringHasher();
            this.namespaces = new Dictionary<String, NamespaceDecl>(hasher);
            AddInitNamespace(String.Empty, String.Empty);
            AddInitNamespace(this.xml, this.xnt.Add(XmlReservedNs.NsXml));
            AddInitNamespace(this.xmlns, this.nsxmlns);
            this.valueType = TypeOfString;
            // init buffer position, etc
            this.inStrm = stream;
            if (data != null) {
                Debug.Assert(len >= 2 && (data[0] == 0xdf && data[1] == 0xff));
                this.data = data;
                this.end = len;
                this.pos = 2;
                this.sniffed = true;
            }
            else {
                this.data = new byte[XmlReader.DefaultBufferSize];
                this.end = stream.Read(this.data, 0, XmlReader.DefaultBufferSize);
                this.pos = 0;
                this.sniffed = false;
            }

            this.mark = -1;
            this.eof = (0 == this.end);
            this.offset = 0;
            this.closeInput = closeInput;
            switch (settings.ConformanceLevel) {
                case ConformanceLevel.Auto:
                    this.docState = 0; break;
                case ConformanceLevel.Fragment:
                    this.docState = 9; break;
                case ConformanceLevel.Document:
                    this.docState = 1; break;
            }
            this.checkCharacters = settings.CheckCharacters;
            this.dtdProcessing = settings.DtdProcessing;
            this.ignoreWhitespace = settings.IgnoreWhitespace;
            this.ignorePIs = settings.IgnoreProcessingInstructions;
            this.ignoreComments = settings.IgnoreComments;

            if (TokenTypeMap == null)
                GenerateTokenTypeMap();
        }
Example #20
0
        //
        // Private methods
        //
        private void Initialize()
        {
            _nameTable = null;
            _lineNumberOffset = 0;
            _linePositionOffset = 0;
            _checkCharacters = true;
            _conformanceLevel = ConformanceLevel.Document;

            _ignoreWhitespace = false;
            _ignorePIs = false;
            _ignoreComments = false;
            _dtdProcessing = DtdProcessing.Prohibit;
            _closeInput = false;

            _maxCharactersFromEntities = 0;
            _maxCharactersInDocument = 0;


            _useAsync = false;

            _isReadOnly = false;
        }
Example #21
0
 public static XmlReaderSettings CreateSettings(ConformanceLevel level, DtdProcessing dtdProcessing, XmlUrlResolver resolver,
                                                XmlSchemaValidationFlags validationFlags, ValidationType validationType, XmlSchemaSet schemaSet, ValidationEventHandler onErrorHandler)
 {
     return(CreateSettings(false, false, true, false, level, dtdProcessing, resolver, validationFlags, validationType, schemaSet, onErrorHandler));
 }
Example #22
0
        internal XmlReader AddConformanceWrapper(XmlReader baseReader)
        {
            XmlReaderSettings baseReaderSettings = baseReader.Settings;
            bool          checkChars             = false;
            bool          noWhitespace           = false;
            bool          noComments             = false;
            bool          noPIs    = false;
            DtdProcessing dtdProc  = (DtdProcessing)(-1);
            bool          needWrap = false;

            if (baseReaderSettings == null)
            {
#pragma warning disable 618

#if SILVERLIGHT
                // Starting from Windows phone 8.1 (TargetsAtLeast_Desktop_V4_5_1) we converge with the desktop behavior so we'll let the reader
                // not throw exception if has different conformance level than Auto.
                if (BinaryCompatibility.TargetsAtLeast_Desktop_V4_5_1)
                {
                    if (this.conformanceLevel != ConformanceLevel.Auto && this.conformanceLevel != XmlReader.GetV1ConformanceLevel(baseReader))
                    {
                        throw new InvalidOperationException(Res.GetString(Res.Xml_IncompatibleConformanceLevel, this.conformanceLevel.ToString()));
                    }
                }
                else if (this.conformanceLevel != ConformanceLevel.Auto)
                {
                    throw new InvalidOperationException(Res.GetString(Res.Xml_IncompatibleConformanceLevel, this.conformanceLevel.ToString()));
                }
#else
                if (this.conformanceLevel != ConformanceLevel.Auto && this.conformanceLevel != XmlReader.GetV1ConformanceLevel(baseReader))
                {
                    throw new InvalidOperationException(Res.GetString(Res.Xml_IncompatibleConformanceLevel, this.conformanceLevel.ToString()));
                }
#endif

#if !SILVERLIGHT
                // get the V1 XmlTextReader ref
                XmlTextReader v1XmlTextReader = baseReader as XmlTextReader;
                if (v1XmlTextReader == null)
                {
                    XmlValidatingReader vr = baseReader as XmlValidatingReader;
                    if (vr != null)
                    {
                        v1XmlTextReader = (XmlTextReader)vr.Reader;
                    }
                }
#endif

                // assume the V1 readers already do all conformance checking;
                // wrap only if IgnoreWhitespace, IgnoreComments, IgnoreProcessingInstructions or ProhibitDtd is true;
                if (this.ignoreWhitespace)
                {
                    WhitespaceHandling wh = WhitespaceHandling.All;
#if !SILVERLIGHT
                    // special-case our V1 readers to see if whey already filter whitespaces
                    if (v1XmlTextReader != null)
                    {
                        wh = v1XmlTextReader.WhitespaceHandling;
                    }
#endif
                    if (wh == WhitespaceHandling.All)
                    {
                        noWhitespace = true;
                        needWrap     = true;
                    }
                }
                if (this.ignoreComments)
                {
                    noComments = true;
                    needWrap   = true;
                }
                if (this.ignorePIs)
                {
                    noPIs    = true;
                    needWrap = true;
                }
                // DTD processing
                DtdProcessing baseDtdProcessing = DtdProcessing.Parse;
#if !SILVERLIGHT
                if (v1XmlTextReader != null)
                {
                    baseDtdProcessing = v1XmlTextReader.DtdProcessing;
                }
#endif
                if ((this.dtdProcessing == DtdProcessing.Prohibit && baseDtdProcessing != DtdProcessing.Prohibit) ||
                    (this.dtdProcessing == DtdProcessing.Ignore && baseDtdProcessing == DtdProcessing.Parse))
                {
                    dtdProc  = this.dtdProcessing;
                    needWrap = true;
                }
#pragma warning restore 618
            }
            else
            {
                if (this.conformanceLevel != baseReaderSettings.ConformanceLevel && this.conformanceLevel != ConformanceLevel.Auto)
                {
                    throw new InvalidOperationException(Res.GetString(Res.Xml_IncompatibleConformanceLevel, this.conformanceLevel.ToString()));
                }
                if (this.checkCharacters && !baseReaderSettings.CheckCharacters)
                {
                    checkChars = true;
                    needWrap   = true;
                }
                if (this.ignoreWhitespace && !baseReaderSettings.IgnoreWhitespace)
                {
                    noWhitespace = true;
                    needWrap     = true;
                }
                if (this.ignoreComments && !baseReaderSettings.IgnoreComments)
                {
                    noComments = true;
                    needWrap   = true;
                }
                if (this.ignorePIs && !baseReaderSettings.IgnoreProcessingInstructions)
                {
                    noPIs    = true;
                    needWrap = true;
                }

                if ((this.dtdProcessing == DtdProcessing.Prohibit && baseReaderSettings.DtdProcessing != DtdProcessing.Prohibit) ||
                    (this.dtdProcessing == DtdProcessing.Ignore && baseReaderSettings.DtdProcessing == DtdProcessing.Parse))
                {
                    dtdProc  = this.dtdProcessing;
                    needWrap = true;
                }
            }

            if (needWrap)
            {
                IXmlNamespaceResolver readerAsNSResolver = baseReader as IXmlNamespaceResolver;
                if (readerAsNSResolver != null)
                {
                    return(new XmlCharCheckingReaderWithNS(baseReader, readerAsNSResolver, checkChars, noWhitespace, noComments, noPIs, dtdProc));
                }
                else
                {
                    return(new XmlCharCheckingReader(baseReader, checkChars, noWhitespace, noComments, noPIs, dtdProc));
                }
            }
            else
            {
                return(baseReader);
            }
        }
        void Initialize(XmlResolver resolver) {
            nameTable = null;
            xmlResolver = (resolver == null ? CreateDefaultResolver() : resolver);
            lineNumberOffset = 0;
            linePositionOffset = 0;
            checkCharacters = true;
            conformanceLevel = ConformanceLevel.Document;

            ignoreWhitespace = false;
            ignorePIs = false;
            ignoreComments = false;
            dtdProcessing = DtdProcessing.Prohibit;
            closeInput = false;

            maxCharactersFromEntities = 0;
            maxCharactersInDocument = 0;

#if !SILVERLIGHT
            schemas = null;
            validationType = ValidationType.None;
            validationFlags = XmlSchemaValidationFlags.ProcessIdentityConstraints;
            validationFlags |= XmlSchemaValidationFlags.AllowXmlAttributes;
#endif

#if ASYNC || FEATURE_NETCORE
            useAsync = false;
#endif

            isReadOnly = false;
#if !SILVERLIGHT
            IsXmlResolverSet = false;
#endif
        }
        public XmlSqlBinaryReader(Stream stream, byte[] data, int len, string baseUri, bool closeInput, XmlReaderSettings settings)
        {
            this.xnt = settings.NameTable;
            if (this.xnt == null)
            {
                this.xnt = new System.Xml.NameTable();
                this.xntFromSettings = false;
            }
            else
            {
                this.xntFromSettings = true;
            }
            this.xml = this.xnt.Add("xml");
            this.xmlns = this.xnt.Add("xmlns");
            this.nsxmlns = this.xnt.Add("http://www.w3.org/2000/xmlns/");
            this.baseUri = baseUri;
            this.state = ScanState.Init;
            this.nodetype = XmlNodeType.None;
            this.token = BinXmlToken.Error;
            this.elementStack = new ElemInfo[0x10];
            this.attributes = new AttrInfo[8];
            this.attrHashTbl = new int[8];
            this.symbolTables.Init();
            this.qnameOther.Clear();
            this.qnameElement.Clear();
            this.xmlspacePreserve = false;
            this.hasher = new SecureStringHasher();
            this.namespaces = new Dictionary<string, NamespaceDecl>(this.hasher);
            this.AddInitNamespace(string.Empty, string.Empty);
            this.AddInitNamespace(this.xml, this.xnt.Add("http://www.w3.org/XML/1998/namespace"));
            this.AddInitNamespace(this.xmlns, this.nsxmlns);
            this.valueType = TypeOfString;
            this.inStrm = stream;
            if (data != null)
            {
                this.data = data;
                this.end = len;
                this.pos = 2;
                this.sniffed = true;
            }
            else
            {
                this.data = new byte[0x1000];
                this.end = stream.Read(this.data, 0, 0x1000);
                this.pos = 0;
                this.sniffed = false;
            }
            this.mark = -1;
            this.eof = 0 == this.end;
            this.offset = 0L;
            this.closeInput = closeInput;
            switch (settings.ConformanceLevel)
            {
                case ConformanceLevel.Auto:
                    this.docState = 0;
                    break;

                case ConformanceLevel.Fragment:
                    this.docState = 9;
                    break;

                case ConformanceLevel.Document:
                    this.docState = 1;
                    break;
            }
            this.checkCharacters = settings.CheckCharacters;
            this.dtdProcessing = settings.DtdProcessing;
            this.ignoreWhitespace = settings.IgnoreWhitespace;
            this.ignorePIs = settings.IgnoreProcessingInstructions;
            this.ignoreComments = settings.IgnoreComments;
            if (TokenTypeMap == null)
            {
                this.GenerateTokenTypeMap();
            }
        }
Example #25
0
        internal XmlReader AddConformanceWrapper(XmlReader baseReader)
        {
            XmlReaderSettings baseReaderSettings = baseReader.Settings;
            bool          checkChars             = false;
            bool          noWhitespace           = false;
            bool          noComments             = false;
            bool          noPIs    = false;
            DtdProcessing dtdProc  = (DtdProcessing)(-1);
            bool          needWrap = false;

            if (baseReaderSettings == null)
            {
#pragma warning disable 618

                if (_conformanceLevel != ConformanceLevel.Auto && _conformanceLevel != XmlReader.GetV1ConformanceLevel(baseReader))
                {
                    throw new InvalidOperationException(SR.Format(SR.Xml_IncompatibleConformanceLevel, _conformanceLevel.ToString()));
                }

                // get the V1 XmlTextReader ref
                XmlTextReader v1XmlTextReader = baseReader as XmlTextReader;
                if (v1XmlTextReader == null)
                {
                    XmlValidatingReader vr = baseReader as XmlValidatingReader;
                    if (vr != null)
                    {
                        v1XmlTextReader = (XmlTextReader)vr.Reader;
                    }
                }

                // assume the V1 readers already do all conformance checking;
                // wrap only if IgnoreWhitespace, IgnoreComments, IgnoreProcessingInstructions or ProhibitDtd is true;
                if (_ignoreWhitespace)
                {
                    WhitespaceHandling wh = WhitespaceHandling.All;
                    // special-case our V1 readers to see if whey already filter whitespaces
                    if (v1XmlTextReader != null)
                    {
                        wh = v1XmlTextReader.WhitespaceHandling;
                    }
                    if (wh == WhitespaceHandling.All)
                    {
                        noWhitespace = true;
                        needWrap     = true;
                    }
                }
                if (_ignoreComments)
                {
                    noComments = true;
                    needWrap   = true;
                }
                if (_ignorePIs)
                {
                    noPIs    = true;
                    needWrap = true;
                }
                // DTD processing
                DtdProcessing baseDtdProcessing = DtdProcessing.Parse;
                if (v1XmlTextReader != null)
                {
                    baseDtdProcessing = v1XmlTextReader.DtdProcessing;
                }

                if ((_dtdProcessing == DtdProcessing.Prohibit && baseDtdProcessing != DtdProcessing.Prohibit) ||
                    (_dtdProcessing == DtdProcessing.Ignore && baseDtdProcessing == DtdProcessing.Parse))
                {
                    dtdProc  = _dtdProcessing;
                    needWrap = true;
                }
#pragma warning restore 618
            }
            else
            {
                if (_conformanceLevel != baseReaderSettings.ConformanceLevel && _conformanceLevel != ConformanceLevel.Auto)
                {
                    throw new InvalidOperationException(SR.Format(SR.Xml_IncompatibleConformanceLevel, _conformanceLevel.ToString()));
                }
                if (_checkCharacters && !baseReaderSettings.CheckCharacters)
                {
                    checkChars = true;
                    needWrap   = true;
                }
                if (_ignoreWhitespace && !baseReaderSettings.IgnoreWhitespace)
                {
                    noWhitespace = true;
                    needWrap     = true;
                }
                if (_ignoreComments && !baseReaderSettings.IgnoreComments)
                {
                    noComments = true;
                    needWrap   = true;
                }
                if (_ignorePIs && !baseReaderSettings.IgnoreProcessingInstructions)
                {
                    noPIs    = true;
                    needWrap = true;
                }

                if ((_dtdProcessing == DtdProcessing.Prohibit && baseReaderSettings.DtdProcessing != DtdProcessing.Prohibit) ||
                    (_dtdProcessing == DtdProcessing.Ignore && baseReaderSettings.DtdProcessing == DtdProcessing.Parse))
                {
                    dtdProc  = _dtdProcessing;
                    needWrap = true;
                }
            }

            if (needWrap)
            {
                IXmlNamespaceResolver readerAsNSResolver = baseReader as IXmlNamespaceResolver;
                if (readerAsNSResolver != null)
                {
                    return(new XmlCharCheckingReaderWithNS(baseReader, readerAsNSResolver, checkChars, noWhitespace, noComments, noPIs, dtdProc));
                }
                else
                {
                    return(new XmlCharCheckingReader(baseReader, checkChars, noWhitespace, noComments, noPIs, dtdProc));
                }
            }
            else
            {
                return(baseReader);
            }
        }
Example #26
0
 public static XmlReaderSettings CreateSettings(ConformanceLevel level, DtdProcessing dtdProcessing, XmlUrlResolver resolver,
                                                XmlSchemaValidationFlags validationFlags, ValidationType validationType)
 {
     return(CreateSettings(false, false, true, false, level, dtdProcessing, resolver, validationFlags, validationType, null, null));
 }