Get the result of a XPath count expression

Topics: User Forum
Jun 28, 2010 at 5: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 11:49 AM

Hi, Andy00,

I found the following approach

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