Help With XML

I have an xml file that I need to read. The format is as follows:

<backup>
  <Project>
    <DirectoryLocation>c:\projects\</DirectoryLocation>
    <ExcludeFolder>\images</ExcludeFolder>
    <Destination>e:\projects\</Destination>
  </Project>
</backup>

I need to write a loop for each project node that gets the values of each of the child nodes. There can be more than one ExcludeFolder.

I'm using the following to iterate through the XML document, but need to modify it to perform some type of loop for each project node.

        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                XmlDocument xml = new XmlDocument();

                try
                {
                    xml.Load(args[0]);

                    foreach (XmlNode node in xml.DocumentElement)
                    {
                        ReadNode(node);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error! Configuration File Not Found.");
                    Console.WriteLine(ex.Message);
                    return;
                }
            }
            else
            {
                Console.WriteLine("Error! No Configuration File Specified.");
            }
        }

        static void ReadNode(XmlNode node)
        {
            Console.WriteLine(node.InnerText);
        }

Thanks for help. This is my first time working with XML so if I have started down the wrong path, feel free to point it out!
LVL 1
clickclickbangAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mrichmonCommented:
Try

foreach (XmlNode node in xml.DocumentElement.ChildNodes)
                    {
                        ReadNode(node);
                    }
0
Carl TawnSystems and Integration DeveloperCommented:
This will grab all of the Project nodes and iterate through its children:


        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(args[0]);

            XmlNodeList nodes = doc.SelectNodes("/backup/Project");

            foreach (XmlNode node in nodes)
            {
                foreach (XmlNode tmp in node.ChildNodes)
                    ReadNode(tmp);
            }

            Console.ReadLine();
        }

        static void ReadNode(XmlNode node)
        {
            Console.WriteLine(node.InnerText);
        }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
clickclickbangAuthor Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.