read xml hierarchy

Posted on 2006-05-28
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:



Any suggestions would be appreciated.

Question by:codequest
    LVL 96

    Expert Comment

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

    2) .NET version?

    LVL 2

    Author Comment

    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
    End Sub

    Sub ReadRecurse(parentNode)
       For each varChild in parent node
    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.
    LVL 96

    Accepted Solution

    No, I can't see any better pattern than what you described with recursion.

    LVL 2

    Author Comment

    Ok.  Thanks for the feedback.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now