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!
1.
1.1
1.2
1.2.1
1.2.2
1.2.3
1.3
2.
etc.
Any suggestions would be appreciated.
Thanks!
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.DocumentE lement.Fir stChild)
End Sub
Sub ReadRecurse(parentNode)
For each varChild in parent node
WriteDisplayIndexForChildN ode(varChi ld)
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.
.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.DocumentE
End Sub
Sub ReadRecurse(parentNode)
For each varChild in parent node
WriteDisplayIndexForChildN
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok. Thanks for the feedback.
2) .NET version?
Bob