tags:

views:

67

answers:

2

I want to use xpath to count occurances of certain node in xml document. What would I use? For ex: If I wanted to get second occurance of movie node I'd use movie[2].

How do I get total number of movie node occurances in document?

A: 

Try count(//movie). See http://msdn.microsoft.com/en-us/library/ms256103.aspx for detail.

KennyTM
@KennyTM: `count(movie)` will get evaluate to the number of `movie` childs of context node. Also, why did you not cite specs but MS documentation instead?
Alejandro
@Alej: The spec doesn't have a clear example.
KennyTM
-1 because this is incorrect w.r.t. the question, "How do I get total number of movie node occurrences in document?"
LarsH
+2  A: 

I want to use xpath to count occurances of certain node in xml document

Use count function. From http://www.w3.org/TR/xpath/#function-count

The count function returns the number of nodes in the argument node-set

So, in your case, this XPath expression:

count(//movie)
Alejandro