clickclickbang
asked on
Help With XML
I have an xml file that I need to read. The format is as follows:
<backup>
<Project>
<DirectoryLocation>c:\proj ects\</Dir ectoryLoca tion>
<ExcludeFolder>\images</Ex cludeFolde r>
<Destination>e:\projects\< /Destinati on>
</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.Messa ge);
return;
}
}
else
{
Console.WriteLine("Error! No Configuration File Specified.");
}
}
static void ReadNode(XmlNode node)
{
Console.WriteLine(node.Inn erText);
}
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!
<backup>
<Project>
<DirectoryLocation>c:\proj
<ExcludeFolder>\images</Ex
<Destination>e:\projects\<
</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.Messa
return;
}
}
else
{
Console.WriteLine("Error! No Configuration File Specified.");
}
}
static void ReadNode(XmlNode node)
{
Console.WriteLine(node.Inn
}
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
foreach (XmlNode node in xml.DocumentElement.ChildN
{
ReadNode(node);
}