Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 count non empty nodes in xml datatype

Author  Topic 

londonstan
Starting Member

2 Posts

Posted - 2009-11-18 : 16:48:16
If i have some xml in the form
<root>
<a>hello</a>
<b>
<bi>hiya</bi>
<bii>hey</bii>
</b>
<c/>
<d>hello again</d>
</root>

how can I

a) count the nodes? i.e. a, b, bi, bii, c, d so 6
b) count the nodes that are non empty a, bi, bii, d so 4

?

i have tried

xmldata.query('count(/root/*)') ))

but that only counts the top level nodes and I have no idea where to start with the non empty nodes

any help will be very much appreciated

londonstan
Starting Member

2 Posts

Posted - 2009-12-06 : 05:46:04
even an idea on where to start would be great
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2009-12-07 : 05:09:33
a) count all the "<" & ">"...divide by 2 and discount the header/trailer pairing?
b) count all the "><" sets ie empty nodes

subtract b from a??

Go to Top of Page
   

- Advertisement -