QueryReaderSettings.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / XmlUtils / System / Xml / Xsl / QueryReaderSettings.cs / 1 / QueryReaderSettings.cs

                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
 
using System.Collections; 
using System.Collections.Generic;
using System.Diagnostics; 
using System.IO;
using System.Xml;

namespace System.Xml.Xsl { 
    internal class QueryReaderSettings {
        private bool               validatingReader; 
        private XmlReaderSettings  xmlReaderSettings; 
        private XmlNameTable       xmlNameTable;
        private EntityHandling     entityHandling; 
        private bool               namespaces;
        private bool               normalization;
        private bool               prohibitDtd;
        private WhitespaceHandling whitespaceHandling; 
        private XmlResolver        xmlResolver;
 
        public QueryReaderSettings(XmlNameTable xmlNameTable) { 
            Debug.Assert(xmlNameTable != null);
            xmlReaderSettings = new XmlReaderSettings(); 
            xmlReaderSettings.NameTable = xmlNameTable;
            xmlReaderSettings.ConformanceLevel = ConformanceLevel.Document;
            xmlReaderSettings.XmlResolver = null;
            xmlReaderSettings.ProhibitDtd = true; 
            xmlReaderSettings.CloseInput = true;
        } 
 
        public QueryReaderSettings(XmlReader reader) {
#pragma warning disable 618 
            XmlValidatingReader valReader = reader as XmlValidatingReader;
#pragma warning restore 618
            if (valReader != null) {
                // Unwrap validation reader 
                validatingReader = true;
                reader = valReader.Impl.Reader; 
            } 
            xmlReaderSettings = reader.Settings;
            if (xmlReaderSettings != null) { 
                xmlReaderSettings = xmlReaderSettings.Clone();
                xmlReaderSettings.NameTable = reader.NameTable;
                xmlReaderSettings.CloseInput = true;
                xmlReaderSettings.LineNumberOffset = 0; 
                xmlReaderSettings.LinePositionOffset = 0;
                XmlTextReaderImpl impl = reader as XmlTextReaderImpl; 
                if (impl != null) { 
                    xmlReaderSettings.XmlResolver = impl.GetResolver();
                } 
            } else {
                xmlNameTable = reader.NameTable;
                XmlTextReader xmlTextReader = reader as XmlTextReader;
                if (xmlTextReader != null) { 
                    XmlTextReaderImpl impl = xmlTextReader.Impl;
                    entityHandling     = impl.EntityHandling; 
                    namespaces         = impl.Namespaces; 
                    normalization      = impl.Normalization;
                    prohibitDtd        = impl.ProhibitDtd; 
                    whitespaceHandling = impl.WhitespaceHandling;
                    xmlResolver        = impl.GetResolver();
                } else {
                    entityHandling     = EntityHandling.ExpandEntities; 
                    namespaces         = true;
                    normalization      = true; 
                    prohibitDtd        = true; 
                    whitespaceHandling = WhitespaceHandling.All;
                    xmlResolver        = null; 
                }
            }
        }
 
        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.ProhibitDtd = prohibitDtd;
                readerImpl.WhitespaceHandling = whitespaceHandling; 
                readerImpl.XmlResolver = xmlResolver; 
                reader = readerImpl;
            } 
            if (validatingReader) {
#pragma warning disable 618
                reader = new XmlValidatingReader(reader);
#pragma warning restore 618 
            }
            return reader; 
        } 

        public XmlNameTable NameTable { 
            get { return xmlReaderSettings != null ? xmlReaderSettings.NameTable : xmlNameTable; }
        }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// [....] 
//-----------------------------------------------------------------------------
 
using System.Collections; 
using System.Collections.Generic;
using System.Diagnostics; 
using System.IO;
using System.Xml;

namespace System.Xml.Xsl { 
    internal class QueryReaderSettings {
        private bool               validatingReader; 
        private XmlReaderSettings  xmlReaderSettings; 
        private XmlNameTable       xmlNameTable;
        private EntityHandling     entityHandling; 
        private bool               namespaces;
        private bool               normalization;
        private bool               prohibitDtd;
        private WhitespaceHandling whitespaceHandling; 
        private XmlResolver        xmlResolver;
 
        public QueryReaderSettings(XmlNameTable xmlNameTable) { 
            Debug.Assert(xmlNameTable != null);
            xmlReaderSettings = new XmlReaderSettings(); 
            xmlReaderSettings.NameTable = xmlNameTable;
            xmlReaderSettings.ConformanceLevel = ConformanceLevel.Document;
            xmlReaderSettings.XmlResolver = null;
            xmlReaderSettings.ProhibitDtd = true; 
            xmlReaderSettings.CloseInput = true;
        } 
 
        public QueryReaderSettings(XmlReader reader) {
#pragma warning disable 618 
            XmlValidatingReader valReader = reader as XmlValidatingReader;
#pragma warning restore 618
            if (valReader != null) {
                // Unwrap validation reader 
                validatingReader = true;
                reader = valReader.Impl.Reader; 
            } 
            xmlReaderSettings = reader.Settings;
            if (xmlReaderSettings != null) { 
                xmlReaderSettings = xmlReaderSettings.Clone();
                xmlReaderSettings.NameTable = reader.NameTable;
                xmlReaderSettings.CloseInput = true;
                xmlReaderSettings.LineNumberOffset = 0; 
                xmlReaderSettings.LinePositionOffset = 0;
                XmlTextReaderImpl impl = reader as XmlTextReaderImpl; 
                if (impl != null) { 
                    xmlReaderSettings.XmlResolver = impl.GetResolver();
                } 
            } else {
                xmlNameTable = reader.NameTable;
                XmlTextReader xmlTextReader = reader as XmlTextReader;
                if (xmlTextReader != null) { 
                    XmlTextReaderImpl impl = xmlTextReader.Impl;
                    entityHandling     = impl.EntityHandling; 
                    namespaces         = impl.Namespaces; 
                    normalization      = impl.Normalization;
                    prohibitDtd        = impl.ProhibitDtd; 
                    whitespaceHandling = impl.WhitespaceHandling;
                    xmlResolver        = impl.GetResolver();
                } else {
                    entityHandling     = EntityHandling.ExpandEntities; 
                    namespaces         = true;
                    normalization      = true; 
                    prohibitDtd        = true; 
                    whitespaceHandling = WhitespaceHandling.All;
                    xmlResolver        = null; 
                }
            }
        }
 
        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.ProhibitDtd = prohibitDtd;
                readerImpl.WhitespaceHandling = whitespaceHandling; 
                readerImpl.XmlResolver = xmlResolver; 
                reader = readerImpl;
            } 
            if (validatingReader) {
#pragma warning disable 618
                reader = new XmlValidatingReader(reader);
#pragma warning restore 618 
            }
            return reader; 
        } 

        public XmlNameTable NameTable { 
            get { return xmlReaderSettings != null ? xmlReaderSettings.NameTable : xmlNameTable; }
        }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK