My xml looks something like this :

<elements>
<elem>
....bunch of other elements
</elem>
</elements>

Is there a way to count the number of occurances of elem tag in some xml file trough linux shell? like with perl/python or anything that might work as one liner?

I might try something like grep -c "elem" myfile.xml and the number I get divide it by 2 and get the number, is there something similar but one liner?

EDIT :

I'm looking for alternative grep solution

Edit
Report