xml - How to get the number of generations of a node? -


i have xml string or file in vb.net. question is, how number of generations node has (going downwards child, grandchild, great grandchild...)?

here code:

dim doc new xmldocument() doc.loadxml(str)  dim root xmlnode = doc.selectsinglenode("/root/subcategory")  if root.haschildnodes     dim integer     = 0 root.childnodes.count - 1         textbox1.appendtext(root.childnodes(i).name)         textbox1.appendtext(vbtab)         textbox1.appendtext(number of generations)         textbox1.appendtext(vbnewline)     next (i) end if 

the xmlnodereader class has depth property can tell depth of current node, this:

dim doc new xmldocument() doc.loadxml(str)  dim deepestnodelevel integer = 0  using nodereader new xmlnodereader(doc)     while nodereader.read()         if nodereader.depth > deepestnode             deepestnodelevel = nodereader.depth         end if     end while end using 

now after going through whole xml document know deepest depth (deepestnodelevel) of element in structure.

adapting posted code, can this:

dim doc new xmldocument() doc.loadxml(str)  using nodereader new xmlnodereader(doc)     while nodereader.read()         textbox1.appendtext(nodereader.name)         textbox1.appendtext(vbtab)         textbox1.appendtext(nodereader.depth.tostring())         textbox1.appendtext(vbnewline)     end while end using 

Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

vb.net - Alternative to the T-SQL AS keyword -