コード例 #1
0
ファイル: XmlNodeExtension.cs プロジェクト: rettigcd/Outfish
        ///// <summary>
        ///// Steps up the tree from the closest parent to the root node returning each node that matches
        ///// </summary>
        //static public IEnumerable<HtmlNode> Parents( this XmlNode root, string cssSelector ) {
        //	return root.Parents().Where( new CssExpression( cssSelector ).IsMatch );
        //}

        /// <summary>
        /// Searches up ancestor tree, starting with self, for first node that matches
        /// </summary>
        static public XmlNode Closest(this XmlNode root, string cssSelector)
        {
            var     cssExpression = new CssExpression(cssSelector);
            XmlNode cur           = root;

            while (cur != null)
            {
                if (cssExpression.IsMatch(cur))
                {
                    return(cur);
                }
                cur = cur.ParentNode;
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Searches up ancestor tree, starting with self, for first node that matches
        /// </summary>
        public HtmlNode Closest(string cssSelector)
        {
            var      cssExpression = new CssExpression(cssSelector);
            HtmlNode cur           = this;

            while (cur != null)
            {
                if (cssExpression.IsMatch(cur))
                {
                    return(cur);
                }
                cur = cur.ParentNode;
            }
            return(null);
        }