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
Post a Comment