예제 #1
0
        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);
            }
        }
예제 #2
0
        // 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.
        }
예제 #3
0
 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.
 }
예제 #4
0
 /// <summary>Gets all descendant nodes in document order.</summary>
 public IEnumerable <HtmlNode> Descendants() => DescendantSearcherHelper.Descendants(this);