示例#1
0
        public void Emit(Token token)
        {
            if (_isEmitPending)
            {
                throw new InvalidOperationException("There is an unread token pending!");
            }

            _emitPending   = token;
            _isEmitPending = true;

            if (token.Type == Token.TokenType.StartTag)
            {
                Token.StartTag startTag = (Token.StartTag)token;

                _lastStartTag = startTag;

                if (startTag.IsSelfClosing)
                {
                    _selfClosingFlagAcknowledged = false;
                }
            }
            else if (token.Type == Token.TokenType.EndTag)
            {
                Token.EndTag endTag = (Token.EndTag)token;

                if (endTag.Attributes != null)
                {
                    Error("Attributes incorrectly present on end tag");
                }
            }
        }
示例#2
0
        /**
         * If the stack contains an element with this tag's name, pop up the stack to remove the first occurrence. If not
         * found, skips.
         *
         * @param endTag
         */
        private void PopStackToClose(Token.EndTag endTag)
        {
            string  elName     = endTag.Name();
            Element firstFound = null;

            IEnumerator <Element> it = _stack.GetDescendingEnumerator();

            while (it.MoveNext())
            {
                Element next = it.Current;
                if (next.NodeName.Equals(elName))
                {
                    firstFound = next;
                    break;
                }
            }
            if (firstFound == null)
            {
                return; // not found, skip
            }

            it = _stack.GetDescendingEnumerator();
            List <Element> remove = new List <Element>();

            while (it.MoveNext())
            {
                Element next = it.Current;
                if (next == firstFound)
                {
                    remove.Add(next);
                    break;
                }
                else
                {
                    remove.Add(next);
                }
            }
            foreach (Element item in remove)
            {
                _stack.Remove(item);
            }
        }