XML Node count
count.xml
#
#
#
#
#
#
#
#
#
#
#
#
Program.cs - This is a console application
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace CountXMLNodes
{
class Program
{
static void Main(string[] args)
{
int countBooks = 0;
int countDVD = 0;
int countGames = 0;
int countOther = 0;
XmlDocument doc = new XmlDocument();
doc.Load("C:\\XML\\count.xml");
foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
switch (node.Name)
{
case "Books":
countBooks++;
break;
case "DVD":
//something.
countDVD++;
break;
case "Games":
//something.
countGames++;
break;
default:
//something.
countOther++;
break;
}
}
Console.WriteLine("Books = " + countBooks);
Console.WriteLine("DVD = " + countDVD);
Console.WriteLine("Games = " + countGames);
Console.WriteLine("Other = "+ countOther);
Console.ReadLine();
}
}
}
No comments:
Post a Comment