Get the result of a XPath count expression

Topics: User Forum
Jun 28, 2010 at 4:31 PM
Hi, I tried to gather what is written in the topic, but with no success. I believed it was sufficient to write: int count = Int32.Parse(page.DocumentNode.SelectSingleNode("count(//div)").InnerText); But I get the error: "The expression must returns a set of nodes".
Jul 3, 2010 at 10:49 AM

Hi, Andy00,

I found the following approach

XPathNavigator nav = page.CreateNavigator();
double count = (double)nav.Evaluate("count(//div)");