10 Ağustos 2009 Pazartesi

Xml dosyalarının .NET Ortamında C# ile Okunup, Yazılması Örnek 2



Örnek 2:

using System;
using System.Xml;
namespace TypeReader
{
class TypeReader
{
static void Main(string[] args)
{
int ws = 0;
int pi = 0;
int dc = 0;
int cc = 0;
int ac = 0;
int et = 0;
int el = 0;
int xd = 0;
// Dosya bitene kadar dökümanı oku
XmlTextReader textReader = new XmlTextReader("C:\\books.xml");
while (textReader.Read())
{
XmlNodeType nType = textReader.NodeType;
// Node Tipi Declaration ise
if (nType == XmlNodeType.XmlDeclaration)
{
Console.WriteLine("Declaration:" + textReader.Name.ToString());
xd = xd + 1;
}
// Node Tipi Comment ise
if (nType == XmlNodeType.Comment)
{
Console.WriteLine("Comment:" + textReader.Name.ToString());
cc = cc + 1;
}
// Node Tipi Attribute ise
if (nType == XmlNodeType.Attribute)
{
Console.WriteLine("Attribute:" + textReader.Name.ToString());
ac = ac + 1;
}
// Node Tipi Element ise
if (nType == XmlNodeType.Element)
{
Console.WriteLine("Element:" + textReader.Name.ToString());
el = el + 1;
}
// Node Tipi Entity ise
if (nType == XmlNodeType.Entity)
{
Console.WriteLine("Entity:" + textReader.Name.ToString());
et = et + 1;
}
// Node Tipi Process Instruction ise
if (nType == XmlNodeType.ProcessingInstruction)
{
Console.WriteLine("Entity:" + textReader.Name.ToString());
pi = pi + 1;
}
// Node Tipi Document ise
if (nType == XmlNodeType.DocumentType)
{
Console.WriteLine("Document:" + textReader.Name.ToString());
dc = dc + 1;
}
// Node Tipi Boşluk ise
if (nType == XmlNodeType.Whitespace)
{
Console.WriteLine("WhiteSpace:" + textReader.Name.ToString());
ws = ws + 1;
}
}
// Sonucu yaz;
Console.WriteLine("Toplam Aciklama Satiri: " + cc.ToString());
Console.WriteLine("Toplam Öznitelik: " + ac.ToString());
Console.WriteLine("Toplam Eleman: " + el.ToString());
Console.WriteLine("Toplam Varlik: " + et.ToString());
Console.WriteLine("Toplam Islem Talimati: " + pi.ToString());
Console.WriteLine("Toplam Bildirim: " + xd.ToString());
Console.WriteLine("Toplam Döküman Tipi: " + dc.ToString());
Console.WriteLine("Toplam Bosluk: " + ws.ToString());
}
}
}

Hiç yorum yok:

Yorum Gönder