Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

read xml hierarchy

Posted on 2006-05-28
4
Medium Priority
?
284 Views
Last Modified: 2010-04-23
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!
0
Comment
Question by:codequest
  • 2
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16785091
1) I don't understand what you are looking for

2) .NET version?

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 16785269
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 16789664
No, I can't see any better pattern than what you described with recursion.

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 16791757
Ok.  Thanks for the feedback.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question