Link to home
Start Free TrialLog in
Avatar of codequest
codequest

asked on

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!
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

1) I don't understand what you are looking for

2) .NET version?

Bob
Avatar of codequest
codequest

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok.  Thanks for the feedback.