Connecting Tech Pros Worldwide Forums | Help | Site Map

Count Nodes

Derek Hart
Guest
 
Posts: n/a
#1: Jun 27 '08
I wish to get a count of nodes in an xml file in vb.net, so I am using the
following, as a simple example:



MyCount = xmlNodePart.Current.Select.//MyNode/Record[*]).Count



I saw in some xml specs that instead of[*] it should be [@*], but that does
not work. Why would the @ symbol be needed?



Derek



Joe Fawcett
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Count Nodes




"Derek Hart" <derekmhart@yahoo.comwrote in message
news:#WL0h6#1IHA.528@TK2MSFTNGP02.phx.gbl...
Quote:
I wish to get a count of nodes in an xml file in vb.net, so I am using the
following, as a simple example:
>
>
>
MyCount = xmlNodePart.Current.Select.//MyNode/Record[*]).Count
>
>
>
I saw in some xml specs that instead of[*] it should be [@*], but that
does not work. Why would the @ symbol be needed?
>
>
>
Derek
>
>
* represents a wildcard for current node type, normally this means all
elements, @ is a shortcut for attributes so @* is all attributes.
If you want all nodes in a file you do //node() or count(//node())
The expression you gave, if it were legal, tries to do something different
altogether. It is fetching the count of those Record elements that have a
parent of MyNode and that have child elements.

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

Closed Thread


Similar .NET Framework bytes