read xml hierarchy

I'm looking for a pattern to list values in a xml document in node-hierachical sequence.  Whatever the "cursor" would be, it would run down into all the child levels of each level before going on to a sibling level, something like this:

1.  
1.1
1.2
1.2.1
1.2.2
1.2.3
1.3
2.

etc.

Any suggestions would be appreciated.

Thanks!
LVL 2
codequestAsked:
Who is Participating?
 
Bob LearnedCommented:
No, I can't see any better pattern than what you described with recursion.

Bob
0
 
Bob LearnedCommented:
1) I don't understand what you are looking for

2) .NET version?

Bob
0
 
codequestAuthor Commented:
Thanks for your reply.  

.Net 2.0

I've got a set of custom routines for working with Gridview data in "outline" format.   It takes a table with "parent/child" fields (pointers within the table rows to other table rows) and creates a "display index" in "outline" sequence, like that shown above (it uses recursion to find all the children/grandchildren, etc of each parent).  It then uses the display index to make a "display table" of table rows, in that sequence, which is the ObjectDataSource for the Gridview.

A well formed XML document is structured like an outline...parents, children, with implied levels and indentations.   I'm looking for a way to read through the nodes of the XML document and build the "display table" described above, in the "outline sequence" of the XML document.

I suspect this can be done with a combination of "ChildNodes" and recursion:
 
Sub Read
   ReadRecurse(XDoc.DocumentElement.FirstChild)
End Sub

Sub ReadRecurse(parentNode)
   For each varChild in parent node
       WriteDisplayIndexForChildNode(varChild)
       ReadRecurse(varChild)
   Next
End Sub

Having written this out, I can see that it's pretty simple...I was wondering if there were any better known patterns or "more automatic" methods for doing this.
0
 
codequestAuthor Commented:
Ok.  Thanks for the feedback.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.