private static HtmlNode PopCurrentNodeParentIfCurrentNodeIsEmptyTag(Stack<HtmlNode> stack, HtmlNode currentNode) { HtmlElementFlag elementFlag; string key = currentNode.Name ?? string.Empty; elementsFlags.TryGetValue(key.ToLower(), out elementFlag); if (elementFlag == HtmlElementFlag.Empty) currentNode = stack.Pop(); return currentNode; }
/// <summary> /// This will return true if the node passed is a descendant of this nodes. /// </summary> /// <param attributeName="nodes">The nodes that might be the parent or grandparent (etc.)</param> /// <returns>True if this nodes is a descendant of the one passed in.</returns> public bool IsDescendantOf(HtmlNode node) { HtmlNode current = this.parent; while (current != null) { if( current == node ) { return true; } current = current.Parent; } return false; }
/// <summary> /// This will return true if the node passed is one of the children or grandchildren of this nodes. /// </summary> /// <param attributeName="nodes">The nodes that might be a child.</param> /// <returns>True if this nodes is an ancestor of the one specified.</returns> public bool IsAncestorOf(HtmlNode node) { if (null != node) return node.IsDescendantOf(this); else return false; }
/// <summary> /// This will return the ancestor that is common to this nodes and the one specified. /// </summary> /// <param attributeName="nodes">The possible nodes that is relative</param> /// <returns>The common ancestor, or null if there is none</returns> public HtmlNode GetCommonAncestor(HtmlNode node) { HtmlNode current = this; while (node != null) { if (this.IsDescendantOf(node)) { return node; } node = node.Parent; } return null; }
public void AppendChild(HtmlNode node) { if (FirstChild == null) FirstChild = node; node.PreviousSibling = LastChild; if (LastChild != null) LastChild.NextSibling = node; LastChild = node; node.ParentNode = this; childNodes.Add(node); }
public void AppendAttribute(HtmlNode attribute) { attributes.Add(attribute); }