示例#1
0
        public void Reset()
        {
            _state = WriteState.Start;
            _attributesToRender.Clear();
            if (_encoder != null)
            {
                _encoder.Reset();
            }

            _manager.Reset();
            for (int i = _elementCount - 1; i >= 0; i--)
            {
                _elements[i].Clear();
            }

            _elementCount = 0;
            _depth        = 0;
            _docPos       = XmlDocumentPosition.BeforeRootElement;
            _attributePrefixGenerationIndex = 0;
            _rootElementAttributes          = null;
            _rootElementPrefix               = null;
            _base64RemainderSize             = 0;
            _pendingBaseDeclarationPrefix    = null;
            _pendingBaseDeclarationNamespace = null;
        }
示例#2
0
        private void WriteStartElementCore(ref string prefix, string localName, string ns)
        {
            if (_state == WriteState.Attribute)
            {
                ThrowBadStateException("WriteStartElement");
            }

            if (localName == null || localName.Length == 0)
            {
                throw new ArgumentNullException(nameof(localName));
            }

            OnPossibleEndOfBase64Content();
            OnPossibleEndOfStartTag(WriteState.Element);
            if (_docPos == XmlDocumentPosition.BeforeRootElement)
            {
                _docPos = XmlDocumentPosition.InRootElement;
            }

            _manager.EnterElementContext();

            if (ns == null)
            {
                if (prefix == null)
                {
                    prefix = string.Empty;
                }

                ns = LookupNamespace(prefix);
                if (ns == null)
                {
                    throw new InvalidOperationException(string.Format("Undefined use of prefix at Element: {0}, {1}", prefix, localName));
                }
            }
            else if (prefix == null)
            {
                prefix = LookupPrefix(ns);
                if (prefix == null)
                {
                    prefix = AutoGeneratePrefix(ns, false);
                }
            }

            _manager.AddLocalNamespaceIfNotRedundant(prefix, ns);
            _manager.MarkToRenderForVisiblyUsedPrefix(prefix, true, _contextProvider);
            PushElement(prefix, localName);
            _attributePrefixGenerationIndex = 0;
        }
        public void EncodeComment(string value, XmlDocumentPosition docPosition)
        {
            if (docPosition == XmlDocumentPosition.AfterRootElement)
            {
                Encode(Char10);
            }

            Encode("<!--");
            EncodeWithLineBreakNormalization(value);
            Encode("-->");

            if (docPosition == XmlDocumentPosition.BeforeRootElement)
            {
                Encode(Char10);
            }
        }
示例#4
0
        private void OnEndElement()
        {
            if (_state != WriteState.Content && _state != WriteState.Element)
            {
                ThrowBadStateException("EndElement");
            }

            OnPossibleEndOfStartTag(WriteState.Content);
            _encoder.EncodeEndElement(_elements[_elementCount - 1].prefix, _elements[_elementCount - 1].localName);
            PopElement();
            _manager.ExitElementContext();
            _depth--;
            if (_depth == 0)
            {
                _docPos = XmlDocumentPosition.AfterRootElement;
                if (EndRootElementCallback != null)
                {
                    EndRootElementCallback.OnEndOfRootElement(this);
                }
            }
        }