HtmlAgilityPack.HtmlNode.SelectNodes C# (CSharp) Method

SelectNodes() public method

Selects a list of nodes matching the XPath expression.
public SelectNodes ( string xpath ) : HtmlAgilityPack.HtmlNodeCollection
xpath string The XPath expression.
return HtmlAgilityPack.HtmlNodeCollection
		public HtmlNodeCollection SelectNodes(string xpath)
		{
			HtmlNodeCollection list = new HtmlNodeCollection(null);
            try
            {
                HtmlNodeNavigator nav = new HtmlNodeNavigator(_ownerdocument, this);
                XPathNodeIterator it = nav.Select(xpath);
                while (it.MoveNext())
                {
                    HtmlNodeNavigator n = (HtmlNodeNavigator)it.Current;
                    list.Add(n.CurrentNode);
                }
            }
            catch (Exception ex)
            {
                ex.log("in HtmlNodeCollection SelectNodes");
            }
            //DC removed this so that we get an empty list when there are no matching nodes
			//if (list.Count == 0)
			//{
			//	return null;
			//}
			return list;
		}

Usage Example

        private EuroMillionsResult ParseResultSection(HtmlNode section)
        {
            var date = DateTime.ParseExact(section.SelectSingleNode(".//div[@class = 'floatLeft']/a").InnerText, "dd/MM/yyyy", CultureInfo.InvariantCulture);

            var balls = section.SelectNodes(".//td[@class = 'euro-ball-s']").Select(x => Convert.ToInt32(x.InnerText));
            var bonusBalls = section.SelectNodes(".//td[@class = 'euro-lucky-star-s']").Select(x => Convert.ToInt32(x.InnerText));

            return new EuroMillionsResult(date, 0, balls.ToList(), bonusBalls.ToList());
        }
All Usage Examples Of HtmlAgilityPack.HtmlNode::SelectNodes