static internal IEnumerable <XmlNode> Descendants(XmlNode root) { Stack <XmlNode> stack = new Stack <XmlNode>(); DescendantSearcherHelper.PushChildrenOntoStack(root, stack); while (stack.Count > 0) { XmlNode node = stack.Pop(); // yield this node yield return(node); // add children to stack DescendantSearcherHelper.PushChildrenOntoStack(node, stack); } }
// finds the highest match in the tree. // for css selectors, once we find a match (except for + and >) // we are just wasting time searching deeper and generating duplicates // ** Once a matching node has been found, it will not search that nodes descendants ** override public IEnumerable <XmlNode> FindDescendantNodes(XmlNode rootNode) { Stack <XmlNode> stack = new Stack <XmlNode>(); DescendantSearcherHelper.PushChildrenOntoStack(rootNode, stack); while (stack.Count > 0) { XmlNode node = stack.Pop(); if (this.Selector.IsMatch(node)) { yield return(node); } else { DescendantSearcherHelper.PushChildrenOntoStack(node, stack); } } // !!! if we matched nth-result, we'd have to do it here. }
override public IEnumerable <XmlNode> FindDescendantNodes(XmlNode rootNode) { return(DescendantSearcherHelper.Descendants(rootNode).Where(this.Selector.IsMatch)); // !!! if we matched nth-result, we'd have to do it here. }
/// <summary>Gets all descendant nodes in document order.</summary> public IEnumerable <HtmlNode> Descendants() => DescendantSearcherHelper.Descendants(this);