Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Count Nodes

Question posted by: Derek Hart (Guest) on June 27th, 2008 07:20 PM
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


Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Joe Fawcett's Avatar
Joe Fawcett
Guest
n/a Posts
June 27th, 2008
07:20 PM
#2

Re: Count Nodes


"Derek Hart" <derekmhart@yahoo.comwrote in message
news:#WL0h6#1IHA.528@TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
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


 
Not the answer you were looking for? Post your question . . .
184,043 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors