Ejemplo n.º 1
0
        /// <summary>
        /// Selects a list of nodes or attributes matching the <see cref="XPath"/> expression.
        /// </summary>
        /// <param name="xpath">The XPath expression.</param>
        /// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or empty collection if no node matched the XPath expression.</returns>
        public HtmlCollection Select(string xpath)
        {
            var list = new HtmlCollection();

            HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
            XPathNodeIterator it  = nav.Select(xpath);

            while (it.MoveNext())
            {
                HtmlNodeNavigator n = (HtmlNodeNavigator)it.Current;
                list.Add(n.Current);
            }
            return(list);
        }
 /// <summary>
 /// Get first instance of node or attribute in supplied collection
 /// </summary>
 /// <param name="items">The collection fo find first node in</param>
 /// <param name="name">Name of the node to find</param>
 /// <returns>First node or attribute with matching name</returns>
 public static IHtmlNode FindFirst(HtmlCollection <T> items, string name)
 {
     foreach (T node in items)
     {
         if (node.Name.ToLower().Contains(name))
         {
             return(node);
         }
         if (!node.HasChildNodes)
         {
             continue;
         }
         IHtmlNode returnNode = HtmlNodeCollection.FindFirst(node.ChildNodes, name);
         if (returnNode != null)
         {
             return(returnNode);
         }
     }
     return(null);
 }