#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15

    How to get all descendant nodes when reading XML?


    I am trying to figure out how to obtain all the descendant nodes for a particular node - is there a property or a method available?

    Here's what I mean:

    Code:
    <node1 abc="1">
      <node2 def="2">
        <node3 ghi="3">
          <node4 jkl="4">
    In above example, say I am at node1 (i.e. I know the name of this node so can obtain the node object) but what I am after is knowing all the descendants of node 1 i.e. node2, node3, and node4 - is there a way to do this?

    Thanks for help!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Posts
    65
    Rep Power
    15
    I was able to get this using recursion...but that doesn't solve my problems completely, I think (not sure as I need to experiment more). FYI, here's the code:

    Code:
    Function ProcessNode(xmlnode)
    
    	sMsg = sMsg & xmlnode.nodeName & vbCrLf
    			
    	If xmlnode.hasChildNodes Then
    		For Each xmlchild In xmlnode.childNodes
    			ProcessNode xmlchild
    		Next
    	End If	
    	
    End Function

IMN logo majestic logo threadwatch logo seochat tools logo