Enumerating XML child nodes (2)

Posted on 2006-03-26
Last Modified: 2012-05-05

I need to enumerate this XML using XMLDocuments class, but without using GetElementsByTagName method, because tag names are not unique. I need the way to enumerate XMLNode childs by name.
Question by:AlexFM
    1 Comment
    LVL 11

    Accepted Solution

    try something like:

            /** Description:
             ** This function recursivly traverses a list of
             ** Xml nodes. Used for testing only.
             ** Author:
             ** Jason Myerscough
            void Traverse(Int32 Index, XmlNodeList Nodes)
                XmlNode CurrentNode = Nodes.Item(Index);

                if (CurrentNode != null)
                    if (CurrentNode.HasChildNodes == true)
                        Traverse(0, CurrentNode.ChildNodes);        // if there is childnodes traverse them

                    Traverse(Index + 1, Nodes);           // traverse the siblings
                    if (CurrentNode.HasChildNodes == false)
                        Console.WriteLine(CurrentNode.Name + " = " + CurrentNode.InnerText);
            }   /** void Traverse(Int32 Index, XmlNodeList Nodes) **/

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    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…

    737 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

    15 Experts available now in Live!

    Get 1:1 Help Now