?
Solved

Enumerating XML child nodes (2)

Posted on 2006-03-26
1
Medium Priority
?
1,045 Views
Last Modified: 2012-05-05
<List>
  <Employees>
      <Name>Peter</Name>
      <Name>John</Name>
  </Employees>
  <Managers>
      <Name>Bill</Name>
  </Managers>
</List>

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.
0
Comment
Question by:AlexFM
1 Comment
 
LVL 11

Accepted Solution

by:
Jase-Coder earned 1500 total points
ID: 16297807
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) **/
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

809 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