Inheritance: XmlWriter
 public QueryOutputWriter(XmlRawWriter writer, XmlWriterSettings settings)
 {
     this.wrapped  = writer;
     this.systemId = settings.DocTypeSystem;
     this.publicId = settings.DocTypePublic;
     if (settings.OutputMethod == XmlOutputMethod.Xml)
     {
         if (this.systemId != null)
         {
             this.outputDocType      = true;
             this.checkWellFormedDoc = true;
         }
         if (settings.AutoXmlDeclaration && (settings.Standalone == XmlStandalone.Yes))
         {
             this.checkWellFormedDoc = true;
         }
         if (settings.CDataSectionElements.Count > 0)
         {
             this.bitsCData        = new BitStack();
             this.lookupCDataElems = new Dictionary <XmlQualifiedName, int>();
             this.qnameCData       = new XmlQualifiedName();
             foreach (XmlQualifiedName name in settings.CDataSectionElements)
             {
                 this.lookupCDataElems[name] = 0;
             }
             this.bitsCData.PushBit(false);
         }
     }
     else if ((settings.OutputMethod == XmlOutputMethod.Html) && ((this.systemId != null) || (this.publicId != null)))
     {
         this.outputDocType = true;
     }
 }
 public QueryOutputWriter(XmlRawWriter writer, XmlWriterSettings settings)
 {
     this.wrapped = writer;
     this.systemId = settings.DocTypeSystem;
     this.publicId = settings.DocTypePublic;
     if (settings.OutputMethod == XmlOutputMethod.Xml)
     {
         if (this.systemId != null)
         {
             this.outputDocType = true;
             this.checkWellFormedDoc = true;
         }
         if (settings.AutoXmlDeclaration && (settings.Standalone == XmlStandalone.Yes))
         {
             this.checkWellFormedDoc = true;
         }
         if (settings.CDataSectionElements.Count > 0)
         {
             this.bitsCData = new BitStack();
             this.lookupCDataElems = new Dictionary<XmlQualifiedName, int>();
             this.qnameCData = new XmlQualifiedName();
             foreach (XmlQualifiedName name in settings.CDataSectionElements)
             {
                 this.lookupCDataElems[name] = 0;
             }
             this.bitsCData.PushBit(false);
         }
     }
     else if ((settings.OutputMethod == XmlOutputMethod.Html) && ((this.systemId != null) || (this.publicId != null)))
     {
         this.outputDocType = true;
     }
 }
 /// <summary>
 /// This constructor is internal so that external users cannot construct it (and therefore we do not have to test it separately).
 /// Initialize output state to accept Rtf content (top-level sequences are therefore prohibited).
 /// </summary>
 internal XmlQueryOutput(XmlQueryRuntime runtime, XmlEventCache xwrt) {
     this.runtime = runtime;
     this.xwrt = xwrt;
     this.xstate = XmlState.WithinContent;
     this.depth = 1;
     this.rootType = XPathNodeType.Root;
 }
Esempio n. 4
0
        /// <summary>
        /// Create either the Html or Xml writer and send any cached events to it.
        /// </summary>
        private void CreateWrappedWriter(XmlOutputMethod outMethod)
        {
            Debug.Assert(_wrapped == null);

            // Create either the Xml or Html writer
            _writerSettings.ReadOnly     = false;
            _writerSettings.OutputMethod = outMethod;

            // If Indent was not set by the user, then default to True for Html
            if (outMethod == XmlOutputMethod.Html && _writerSettings.IndentInternal == TriState.Unknown)
            {
                _writerSettings.Indent = true;
            }

            _writerSettings.ReadOnly = true;

            if (_textWriter != null)
            {
                _wrapped = ((XmlWellFormedWriter)XmlWriter.Create(_textWriter, _writerSettings)).RawWriter;
            }
            else
            {
                _wrapped = ((XmlWellFormedWriter)XmlWriter.Create(_strm, _writerSettings)).RawWriter;
            }

            // Send cached events to the new writer
            _eventCache.EndEvents();
            _eventCache.EventsToWriter(_wrapped);

            // Send OnRemoveWriter event
            if (_onRemove != null)
            {
                (this._onRemove)(_wrapped);
            }
        }
        /// <summary>
        /// The wrapped writer will callback on this method if it wishes to remove itself from the pipeline.
        /// </summary>
        private void SetWrappedWriter(XmlRawWriter writer) {
            // If new writer might remove itself from pipeline, have it callback on this method when its ready to go
            IRemovableWriter removable = writer as IRemovableWriter;
            if (removable != null)
                removable.OnRemoveWriterEvent = SetWrappedWriter;

            this.wrapped = writer;
        }
Esempio n. 6
0
 /// <summary>
 /// This constructor is internal so that external users cannot construct it (and therefore we do not have to test it separately).
 /// Initialize output state to accept Rtf content (top-level sequences are therefore prohibited).
 /// </summary>
 internal XmlQueryOutput(XmlQueryRuntime runtime, XmlEventCache xwrt)
 {
     _runtime = runtime;
     _xwrt = xwrt;
     _xstate = XmlState.WithinContent;
     _depth = 1;
     _rootType = XPathNodeType.Root;
 }
Esempio n. 7
0
 /// <summary>
 /// Start construction of a new Xml tree (document or fragment).
 /// </summary>
 public override XmlRawWriter StartTree(XPathNodeType rootType, IXmlNamespaceResolver nsResolver, XmlNameTable nameTable) {
     // Build XPathDocument
     // If rootType != XPathNodeType.Root, then build an XQuery fragment
     this.doc = new XPathDocument(nameTable);
     this.writer = doc.LoadFromWriter(XPathDocument.LoadFlags.AtomizeNames | (rootType == XPathNodeType.Root ? XPathDocument.LoadFlags.None : XPathDocument.LoadFlags.Fragment), string.Empty);
     this.writer.NamespaceResolver = nsResolver;
     return this.writer;
 }
        private int hashCodeUnion;              // Set of hash bits that can quickly guarantee a name is not a duplicate

        /// <summary>
        /// Initialize the cache.  Use this method instead of a constructor in order to reuse the cache.
        /// </summary>
        public void Init(XmlRawWriter wrapped) {
            SetWrappedWriter(wrapped);

            // Clear attribute list
            this.numEntries = 0;
            this.idxLastName = 0;
            this.hashCodeUnion = 0;
        }
Esempio n. 9
0
        public QueryOutputWriter(XmlRawWriter writer, XmlWriterSettings settings)
        {
            this.wrapped = writer;

            this.systemId = settings.DocTypeSystem;
            this.publicId = settings.DocTypePublic;

            if (settings.OutputMethod == XmlOutputMethod.Xml)
            {
                // Xml output method shouldn't output doc-type-decl if system ID is not defined (even if public ID is)
                // Only check for well-formed document if output method is xml
                if (this.systemId != null)
                {
                    this.outputDocType      = true;
                    this.checkWellFormedDoc = true;
                }

                // Check for well-formed document if standalone="yes" in an auto-generated xml declaration
                if (settings.AutoXmlDeclaration && settings.Standalone == XmlStandalone.Yes)
                {
                    this.checkWellFormedDoc = true;
                }

                this.listCDataElems = settings.CDataSectionElements;
                if (this.listCDataElems != null)
                {
                    this.bitsCData        = new BitStack();
                    this.lookupCDataElems = new Hashtable();
                    this.qnameCData       = new XmlQualifiedName();

                    // Add each element name to the lookup table
                    foreach (object name in this.listCDataElems)
                    {
                        if (name is string)
                        {
                            XmlQualifiedName qname = new XmlQualifiedName(name as string, "");
                            this.lookupCDataElems[qname] = qname;
                        }
                        else
                        {
                            Debug.Assert(name is XmlQualifiedName);
                            this.lookupCDataElems[name] = name;
                        }
                    }

                    this.bitsCData.PushBit(false);
                }
            }
            else if (settings.OutputMethod == XmlOutputMethod.Html)
            {
                // Html output method should output doc-type-decl if system ID or public ID is defined
                if (this.systemId != null || this.publicId != null)
                {
                    this.outputDocType = true;
                }
            }
        }
 internal async Task WriteDeclAsync(XmlWriter writer, XmlRawWriter rawWriter) {
     Debug.Assert(kind == NamespaceKind.NeedToWrite);
     if (null != rawWriter) {
         await rawWriter.WriteNamespaceDeclarationAsync(prefix, namespaceUri).ConfigureAwait(false);
     }
     else {
         if (prefix.Length == 0) {
             await writer.WriteStartAttributeAsync(string.Empty, "xmlns", XmlReservedNs.NsXmlNs).ConfigureAwait(false);
         }
         else {
             await writer.WriteStartAttributeAsync("xmlns", prefix, XmlReservedNs.NsXmlNs).ConfigureAwait(false);
         }
         await writer.WriteStringAsync(namespaceUri).ConfigureAwait(false);
         await writer.WriteEndAttributeAsync().ConfigureAwait(false);
     }
 }
Esempio n. 11
0
        public QueryOutputWriter(XmlRawWriter writer, XmlWriterSettings settings)
        {
            _wrapped = writer;

            _systemId = settings.DocTypeSystem;
            _publicId = settings.DocTypePublic;

            if (settings.OutputMethod == XmlOutputMethod.Xml)
            {
                // Xml output method shouldn't output doc-type-decl if system ID is not defined (even if public ID is)
                // Only check for well-formed document if output method is xml
                if (_systemId != null)
                {
                    _outputDocType      = true;
                    _checkWellFormedDoc = true;
                }

                // Check for well-formed document if standalone="yes" in an auto-generated xml declaration
                if (settings.AutoXmlDeclaration && settings.Standalone == XmlStandalone.Yes)
                {
                    _checkWellFormedDoc = true;
                }

                if (settings.CDataSectionElements.Count > 0)
                {
                    _bitsCData        = new BitStack();
                    _lookupCDataElems = new Dictionary <XmlQualifiedName, int>();
                    _qnameCData       = new XmlQualifiedName();

                    // Add each element name to the lookup table
                    foreach (XmlQualifiedName name in settings.CDataSectionElements)
                    {
                        _lookupCDataElems[name] = 0;
                    }

                    _bitsCData.PushBit(false);
                }
            }
            else if (settings.OutputMethod == XmlOutputMethod.Html)
            {
                // Html output method should output doc-type-decl if system ID or public ID is defined
                if (_systemId != null || _publicId != null)
                {
                    _outputDocType = true;
                }
            }
        }
        public QueryOutputWriter(XmlRawWriter writer, XmlWriterSettings settings) {
            this.wrapped = writer;

            this.systemId = settings.DocTypeSystem;
            this.publicId = settings.DocTypePublic;

            if (settings.OutputMethod == XmlOutputMethod.Xml) {
                // Xml output method shouldn't output doc-type-decl if system ID is not defined (even if public ID is)
                // Only check for well-formed document if output method is xml
                if (this.systemId != null) {
                    this.outputDocType = true;
                    this.checkWellFormedDoc = true;
                }

                // Check for well-formed document if standalone="yes" in an auto-generated xml declaration
                if (settings.AutoXmlDeclaration && settings.Standalone == XmlStandalone.Yes)
                    this.checkWellFormedDoc = true;

                this.listCDataElems = settings.CDataSectionElements;
                if (this.listCDataElems != null) {
                    this.bitsCData = new BitStack();
                    this.lookupCDataElems = new Hashtable();
                    this.qnameCData = new XmlQualifiedName();

                    // Add each element name to the lookup table
                    foreach (object name in this.listCDataElems) {
                        if (name is string) {
                            XmlQualifiedName qname = new XmlQualifiedName(name as string, "");
                            this.lookupCDataElems[qname] = qname;
                        }
                        else {
                            Debug.Assert(name is XmlQualifiedName);
                            this.lookupCDataElems[name] = name;
                        }
                    }

                    this.bitsCData.PushBit(false);
                }
            }
            else if (settings.OutputMethod == XmlOutputMethod.Html) {
                // Html output method should output doc-type-decl if system ID or public ID is defined
                if (this.systemId != null || this.publicId != null)
                    this.outputDocType = true;
            }
        }
Esempio n. 13
0
        public QueryOutputWriter(XmlRawWriter writer, XmlWriterSettings settings)
        {
            _wrapped = writer;

            _systemId = settings.DocTypeSystem;
            _publicId = settings.DocTypePublic;

            if (settings.OutputMethod == XmlOutputMethod.Xml)
            {
                // Xml output method shouldn't output doc-type-decl if system ID is not defined (even if public ID is)
                // Only check for well-formed document if output method is xml
                if (_systemId != null)
                {
                    _outputDocType = true;
                    _checkWellFormedDoc = true;
                }

                // Check for well-formed document if standalone="yes" in an auto-generated xml declaration
                if (settings.AutoXmlDeclaration && settings.Standalone == XmlStandalone.Yes)
                    _checkWellFormedDoc = true;

                if (settings.CDataSectionElements.Count > 0)
                {
                    _bitsCData = new BitStack();
                    _lookupCDataElems = new Dictionary<XmlQualifiedName, int>();
                    _qnameCData = new XmlQualifiedName();

                    // Add each element name to the lookup table
                    foreach (XmlQualifiedName name in settings.CDataSectionElements)
                    {
                        _lookupCDataElems[name] = 0;
                    }

                    _bitsCData.PushBit(false);
                }
            }
            else if (settings.OutputMethod == XmlOutputMethod.Html)
            {
                // Html output method should output doc-type-decl if system ID or public ID is defined
                if (_systemId != null || _publicId != null)
                    _outputDocType = true;
            }
        }
Esempio n. 14
0
 internal void WriteDecl(XmlWriter writer, XmlRawWriter rawWriter)
 {
     Debug.Assert(kind == NamespaceKind.NeedToWrite);
     if (null != rawWriter)
     {
         rawWriter.WriteNamespaceDeclaration(prefix, namespaceUri);
     }
     else
     {
         if (prefix.Length == 0)
         {
             writer.WriteStartAttribute(string.Empty, "xmlns", XmlReservedNs.NsXmlNs);
         }
         else
         {
             writer.WriteStartAttribute("xmlns", prefix, XmlReservedNs.NsXmlNs);
         }
         writer.WriteString(namespaceUri);
         writer.WriteEndAttribute();
     }
 }
            internal async Task WriteDeclAsync(XmlWriter writer, XmlRawWriter rawWriter)
            {
                Debug.Assert(kind == NamespaceKind.NeedToWrite);
                if (null != rawWriter)
                {
                    await rawWriter.WriteNamespaceDeclarationAsync(prefix, namespaceUri).ConfigureAwait(false);
                }
                else
                {
                    if (prefix.Length == 0)
                    {
                        await writer.WriteStartAttributeAsync(string.Empty, "xmlns", XmlReservedNs.NsXmlNs).ConfigureAwait(false);
                    }
                    else
                    {
                        await writer.WriteStartAttributeAsync("xmlns", prefix, XmlReservedNs.NsXmlNs).ConfigureAwait(false);
                    }
                    await writer.WriteStringAsync(namespaceUri).ConfigureAwait(false);

                    await writer.WriteEndAttributeAsync().ConfigureAwait(false);
                }
            }
 private void CreateWrappedWriter(XmlOutputMethod outMethod)
 {
     this.writerSettings.ReadOnly     = false;
     this.writerSettings.OutputMethod = outMethod;
     if ((outMethod == XmlOutputMethod.Html) && (this.writerSettings.IndentInternal == TriState.Unknown))
     {
         this.writerSettings.Indent = true;
     }
     this.writerSettings.ReadOnly = true;
     if (this.textWriter != null)
     {
         this.wrapped = ((XmlWellFormedWriter)XmlWriter.Create(this.textWriter, this.writerSettings)).RawWriter;
     }
     else
     {
         this.wrapped = ((XmlWellFormedWriter)XmlWriter.Create(this.strm, this.writerSettings)).RawWriter;
     }
     this.eventCache.EndEvents();
     this.eventCache.EventsToWriter(this.wrapped);
     if (this.onRemove != null)
     {
         this.onRemove(this.wrapped);
     }
 }
 private void CreateWrappedWriter(XmlOutputMethod outMethod)
 {
     this.writerSettings.ReadOnly = false;
     this.writerSettings.OutputMethod = outMethod;
     if ((outMethod == XmlOutputMethod.Html) && (this.writerSettings.IndentInternal == TriState.Unknown))
     {
         this.writerSettings.Indent = true;
     }
     this.writerSettings.ReadOnly = true;
     if (this.textWriter != null)
     {
         this.wrapped = ((XmlWellFormedWriter) XmlWriter.Create(this.textWriter, this.writerSettings)).RawWriter;
     }
     else
     {
         this.wrapped = ((XmlWellFormedWriter) XmlWriter.Create(this.strm, this.writerSettings)).RawWriter;
     }
     this.eventCache.EndEvents();
     this.eventCache.EventsToWriter(this.wrapped);
     if (this.onRemove != null)
     {
         this.onRemove(this.wrapped);
     }
 }
Esempio n. 18
0
 internal XmlRawWriterBase64Encoder(XmlRawWriter rawWriter)
 {
     _rawWriter = rawWriter;
 }
Esempio n. 19
0
        public void EventsToWriter(XmlWriter writer)
        {
            if (this.singleText.Count != 0)
            {
                writer.WriteString(this.singleText.GetResult());
            }
            else
            {
                XmlRawWriter writer2 = writer as XmlRawWriter;
                for (int i = 0; i < this.pages.Count; i++)
                {
                    XmlEvent[] eventArray = this.pages[i];
                    for (int j = 0; j < eventArray.Length; j++)
                    {
                        byte[] buffer;
                        switch (eventArray[j].EventType)
                        {
                        case XmlEventType.Unknown:
                            return;

                        case XmlEventType.DocType:
                        {
                            writer.WriteDocType(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3, (string)eventArray[j].Object);
                            continue;
                        }

                        case XmlEventType.StartElem:
                        {
                            writer.WriteStartElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.StartAttr:
                        {
                            writer.WriteStartAttribute(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.EndAttr:
                        {
                            writer.WriteEndAttribute();
                            continue;
                        }

                        case XmlEventType.CData:
                        {
                            writer.WriteCData(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.Comment:
                        {
                            writer.WriteComment(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.PI:
                        {
                            writer.WriteProcessingInstruction(eventArray[j].String1, eventArray[j].String2);
                            continue;
                        }

                        case XmlEventType.Whitespace:
                        {
                            writer.WriteWhitespace(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.String:
                        {
                            writer.WriteString(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.Raw:
                        {
                            writer.WriteRaw(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.EntRef:
                        {
                            writer.WriteEntityRef(eventArray[j].String1);
                            continue;
                        }

                        case XmlEventType.CharEnt:
                        {
                            writer.WriteCharEntity((char)eventArray[j].Object);
                            continue;
                        }

                        case XmlEventType.SurrCharEnt:
                        {
                            char[] chArray = (char[])eventArray[j].Object;
                            writer.WriteSurrogateCharEntity(chArray[0], chArray[1]);
                            continue;
                        }

                        case XmlEventType.Base64:
                        {
                            buffer = (byte[])eventArray[j].Object;
                            writer.WriteBase64(buffer, 0, buffer.Length);
                            continue;
                        }

                        case XmlEventType.BinHex:
                        {
                            buffer = (byte[])eventArray[j].Object;
                            writer.WriteBinHex(buffer, 0, buffer.Length);
                            continue;
                        }

                        case XmlEventType.XmlDecl1:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteXmlDeclaration((XmlStandalone)eventArray[j].Object);
                            }
                            continue;
                        }

                        case XmlEventType.XmlDecl2:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteXmlDeclaration(eventArray[j].String1);
                            }
                            continue;
                        }

                        case XmlEventType.StartContent:
                        {
                            if (writer2 != null)
                            {
                                writer2.StartElementContent();
                            }
                            continue;
                        }

                        case XmlEventType.EndElem:
                        {
                            if (writer2 == null)
                            {
                                break;
                            }
                            writer2.WriteEndElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.FullEndElem:
                        {
                            if (writer2 == null)
                            {
                                goto Label_0367;
                            }
                            writer2.WriteFullEndElement(eventArray[j].String1, eventArray[j].String2, eventArray[j].String3);
                            continue;
                        }

                        case XmlEventType.Nmsp:
                        {
                            if (writer2 == null)
                            {
                                goto Label_0394;
                            }
                            writer2.WriteNamespaceDeclaration(eventArray[j].String1, eventArray[j].String2);
                            continue;
                        }

                        case XmlEventType.EndBase64:
                        {
                            if (writer2 != null)
                            {
                                writer2.WriteEndBase64();
                            }
                            continue;
                        }

                        case XmlEventType.Close:
                        {
                            writer.Close();
                            continue;
                        }

                        case XmlEventType.Flush:
                        {
                            writer.Flush();
                            continue;
                        }

                        case XmlEventType.Dispose:
                        {
                            writer.Dispose();
                            continue;
                        }

                        default:
                        {
                            continue;
                        }
                        }
                        writer.WriteEndElement();
                        continue;
Label_0367:
                        writer.WriteFullEndElement();
                        continue;
Label_0394:
                        writer.WriteAttributeString("xmlns", eventArray[j].String1, "http://www.w3.org/2000/xmlns/", eventArray[j].String2);
                    }
                }
            }
        }
Esempio n. 20
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public XmlMergeSequenceWriter(XmlRawWriter xwrt) {
     this.xwrt = xwrt;
     this.lastItemWasAtomic = false;
 }
        /// <summary>
        /// Before calling XmlRawWriter.WriteStartElement(), perform various checks to ensure well-formedness.
        /// </summary>
        public override void WriteStartElement(string prefix, string localName, string ns) {
            Debug.Assert(prefix != null && localName != null && localName.Length != 0 && ns != null, "Invalid argument");
            Debug.Assert(ValidateNames.ValidateName(prefix, localName, ns, XPathNodeType.Element, ValidateNames.Flags.All), "Name validation failed");

            // Xml state transitions
            ConstructWithinContent(XPathNodeType.Element);

            // Call XmlRawWriter.WriteStartElement
            WriteStartElementUnchecked(prefix, localName, ns);

            // Ensure that element's namespace declaration is declared
            WriteNamespaceDeclarationUnchecked(prefix, ns);

            // Cache attributes in order to detect duplicates
            if (this.attrCache == null)
                this.attrCache = new XmlAttributeCache();

            this.attrCache.Init(Writer);
            Writer = this.attrCache;
            this.attrCache = null;

            // Push element names onto a stack
            PushElementNames(prefix, localName, ns);
        }
        //
        // Constructor & finalizer
        //
        internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings) {
            Debug.Assert(writer != null);
            Debug.Assert(settings != null);
            Debug.Assert(MaxNamespacesWalkCount <= 3);

            this.writer = writer;

            rawWriter = writer as XmlRawWriter;
            predefinedNamespaces = writer as IXmlNamespaceResolver;
            if (rawWriter != null) {
                rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
            }

            checkCharacters = settings.CheckCharacters;

            conformanceLevel = settings.ConformanceLevel;
            stateTable = (conformanceLevel == ConformanceLevel.Document) ? StateTableDocument : StateTableAuto;

            currentState = State.Start;

            nsStack = new Namespace[NamespaceStackInitialSize];
            nsStack[0].Set("xmlns", XmlReservedNs.NsXmlNs, NamespaceKind.Special);
            nsStack[1].Set("xml", XmlReservedNs.NsXml, NamespaceKind.Special);
            if (predefinedNamespaces == null) {
                nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
            }
            else {
                string defaultNs = predefinedNamespaces.LookupNamespace(string.Empty);
                nsStack[2].Set(string.Empty, (defaultNs == null ? string.Empty : defaultNs), NamespaceKind.Implied);
            }
            nsTop = 2;

            elemScopeStack = new ElementScope[ElementStackInitialSize];
            elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, nsTop);
            elemScopeStack[0].xmlSpace = XmlSpace.None;
            elemScopeStack[0].xmlLang = null;
            elemTop = 0;

            attrStack = new AttrName[AttributeArrayInitialSize];

            attrValue = new StringBuilder();

            hasher = new SecureStringHasher();
        }
        //
        // Constructor & finalizer
        //
        internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings)
        {
            Debug.Assert(writer != null);
            Debug.Assert(settings != null);
            Debug.Assert(MaxNamespacesWalkCount <= 3);

            _writer = writer;

            _rawWriter = writer as XmlRawWriter;
            _predefinedNamespaces = writer as IXmlNamespaceResolver;
            if (_rawWriter != null)
            {
                _rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
            }

            _checkCharacters = settings.CheckCharacters;
            _omitDuplNamespaces = (settings.NamespaceHandling & NamespaceHandling.OmitDuplicates) != 0;
            _writeEndDocumentOnClose = settings.WriteEndDocumentOnClose;

            _conformanceLevel = settings.ConformanceLevel;
            _stateTable = (_conformanceLevel == ConformanceLevel.Document) ? s_stateTableDocument : s_stateTableAuto;

            _currentState = State.Start;

            _nsStack = new Namespace[NamespaceStackInitialSize];
            _nsStack[0].Set("xmlns", XmlReservedNs.NsXmlNs, NamespaceKind.Special);
            _nsStack[1].Set("xml", XmlReservedNs.NsXml, NamespaceKind.Special);
            if (_predefinedNamespaces == null)
            {
                _nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
            }
            else
            {
                string defaultNs = _predefinedNamespaces.LookupNamespace(string.Empty);
                _nsStack[2].Set(string.Empty, (defaultNs == null ? string.Empty : defaultNs), NamespaceKind.Implied);
            }
            _nsTop = 2;

            _elemScopeStack = new ElementScope[ElementStackInitialSize];
            _elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, _nsTop);
            _elemScopeStack[0].xmlSpace = XmlSpace.None;
            _elemScopeStack[0].xmlLang = null;
            _elemTop = 0;

            _attrStack = new AttrName[AttributeArrayInitialSize];

            _hasher = new SecureStringHasher();
        }
 internal Task WriteFullEndElementAsync(XmlRawWriter rawWriter)
 {
     return rawWriter.WriteFullEndElementAsync(prefix, localName, namespaceUri);
 }
 internal void WriteFullEndElement(XmlRawWriter rawWriter)
 {
     rawWriter.WriteFullEndElement(this.prefix, this.localName, this.namespaceUri);
 }
Esempio n. 26
0
 internal void WriteDecl(XmlWriter writer, XmlRawWriter rawWriter)
 {
     Debug.Assert(kind == NamespaceKind.NeedToWrite);
     if (null != rawWriter)
     {
         rawWriter.WriteNamespaceDeclaration(prefix, namespaceUri);
     }
     else
     {
         if (prefix.Length == 0)
         {
             writer.WriteStartAttribute(string.Empty, XmlConst.NsXmlNs, XmlConst.ReservedNsXmlNs);
         }
         else
         {
             writer.WriteStartAttribute(XmlConst.NsXmlNs, prefix, XmlConst.ReservedNsXmlNs);
         }
         writer.WriteString(namespaceUri);
         writer.WriteEndAttribute();
     }
 }
Esempio n. 27
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public XmlMergeSequenceWriter(XmlRawWriter xwrt)
 {
     _xwrt = xwrt;
     _lastItemWasAtomic = false;
 }
 internal void WriteDecl(XmlWriter writer, XmlRawWriter rawWriter)
 {
     if (rawWriter != null)
     {
         rawWriter.WriteNamespaceDeclaration(this.prefix, this.namespaceUri);
     }
     else
     {
         if (this.prefix.Length == 0)
         {
             writer.WriteStartAttribute(string.Empty, "xmlns", "http://www.w3.org/2000/xmlns/");
         }
         else
         {
             writer.WriteStartAttribute("xmlns", this.prefix, "http://www.w3.org/2000/xmlns/");
         }
         writer.WriteString(this.namespaceUri);
         writer.WriteEndAttribute();
     }
 }
        /// <summary>
        /// Create either the Html or Xml writer and send any cached events to it.
        /// </summary>
        private void CreateWrappedWriter(XmlOutputMethod outMethod) {
            Debug.Assert(this.wrapped == null);

            // Create either the Xml or Html writer
            this.writerSettings.ReadOnly = false;
            this.writerSettings.OutputMethod = outMethod;

            // If Indent was not set by the user, then default to True for Html
            if (outMethod == XmlOutputMethod.Html && this.writerSettings.IndentInternal == TriState.Unknown)
                this.writerSettings.Indent = true;

            this.writerSettings.ReadOnly = true;

            if (textWriter != null)
                this.wrapped = ((XmlWellFormedWriter)XmlWriter.Create(this.textWriter, this.writerSettings)).RawWriter;
            else
                this.wrapped = ((XmlWellFormedWriter)XmlWriter.Create(this.strm, this.writerSettings)).RawWriter;

            // Send cached events to the new writer
            this.eventCache.EndEvents();
            this.eventCache.EventsToWriter(this.wrapped);

            // Send OnRemoveWriter event
            if (this.onRemove != null)
                (this.onRemove)(this.wrapped);
        }
 internal XmlRawWriterBase64Encoder( XmlRawWriter rawWriter ) {
     this.rawWriter = rawWriter;
 }
Esempio n. 31
0
 internal void WriteFullEndElement(XmlRawWriter rawWriter)
 {
     rawWriter.WriteFullEndElement(prefix, localName, namespaceUri);
 }
        /// <summary>
        /// This method will be called if "xwrt" is a writer which no longer needs to be part of the pipeline and
        /// wishes to replace itself with a different writer.  For example, the auto-detect writer replaces itself
        /// with the Html or Xml writer once it has determined which output mode to use.
        /// </summary>
        private void SetWrappedWriter(XmlRawWriter writer) {
            // Reuse XmlAttributeCache so that it doesn't have to be recreated every time
            if (Writer is XmlAttributeCache)
                this.attrCache = (XmlAttributeCache) Writer;

            Writer = writer;
        }
Esempio n. 33
0
 internal void WriteFullEndElement(XmlRawWriter rawWriter)
 {
     rawWriter.WriteFullEndElement(prefix, localName, namespaceUri);
 }
 internal Task WriteFullEndElementAsync(XmlRawWriter rawWriter)
 {
     return(rawWriter.WriteFullEndElementAsync(prefix, localName, namespaceUri));
 }
 internal NavigatorOutput(string baseUri) {
     doc = new XPathDocument();
     this.wr = doc.LoadFromWriter(XPathDocument.LoadFlags.AtomizeNames, baseUri);
 }
 internal XmlWellFormedWriter(XmlWriter writer, XmlWriterSettings settings)
 {
     this.writer = writer;
     this.rawWriter = writer as XmlRawWriter;
     this.predefinedNamespaces = writer as IXmlNamespaceResolver;
     if (this.rawWriter != null)
     {
         this.rawWriter.NamespaceResolver = new NamespaceResolverProxy(this);
     }
     this.checkCharacters = settings.CheckCharacters;
     this.omitDuplNamespaces = (settings.NamespaceHandling & NamespaceHandling.OmitDuplicates) != NamespaceHandling.Default;
     this.conformanceLevel = settings.ConformanceLevel;
     this.stateTable = (this.conformanceLevel == ConformanceLevel.Document) ? StateTableDocument : StateTableAuto;
     this.currentState = State.Start;
     this.nsStack = new Namespace[8];
     this.nsStack[0].Set("xmlns", "http://www.w3.org/2000/xmlns/", NamespaceKind.Special);
     this.nsStack[1].Set("xml", "http://www.w3.org/XML/1998/namespace", NamespaceKind.Special);
     if (this.predefinedNamespaces == null)
     {
         this.nsStack[2].Set(string.Empty, string.Empty, NamespaceKind.Implied);
     }
     else
     {
         string str = this.predefinedNamespaces.LookupNamespace(string.Empty);
         this.nsStack[2].Set(string.Empty, (str == null) ? string.Empty : str, NamespaceKind.Implied);
     }
     this.nsTop = 2;
     this.elemScopeStack = new ElementScope[8];
     this.elemScopeStack[0].Set(string.Empty, string.Empty, string.Empty, this.nsTop);
     this.elemScopeStack[0].xmlSpace = System.Xml.XmlSpace.None;
     this.elemScopeStack[0].xmlLang = null;
     this.elemTop = 0;
     this.attrStack = new AttrName[8];
     this.hasher = new SecureStringHasher();
 }