/// <summary> /// If the stack contains an element with this tag's name, pop up the stack to remove the first occurrence. /// </summary> /// <remarks> /// If not found, skips. /// </remarks> /// <param name="endTag"></param> private void PopStackToClose(Token.EndTag endTag) { string elName = endTag.Name(); Element firstFound = null; var it = stack.GetDescendingEnumerator(); while (it.MoveNext()) { Element next = it.Current; if (next.NodeName.Equals(elName)) { firstFound = next; break; } } if (firstFound == null) { // not found, skip return; } it = stack.GetDescendingEnumerator(); while (it.MoveNext()) { Element next = it.Current; if (next == firstFound) { it.Remove(); break; } else { it.Remove(); } } }
internal void Emit(Token token) { Validate.IsFalse(isEmitPending, "There is an unread token pending!"); emitPending = token; isEmitPending = true; if (token.type == TokenType.StartTag) { Token.StartTag startTag = (Token.StartTag)token; lastStartTag = startTag; if (startTag.selfClosing) { selfClosingFlagAcknowledged = false; } } else { if (token.type == TokenType.EndTag) { Token.EndTag endTag = (Token.EndTag)token; if (endTag.attributes != null) { Error("Attributes incorrectly present on end tag"); } } } }