به نام خدا سلام بر برنامه نویسان عزیز 😉 در این پست کد خواندن XML document بر اساس نوع node در سی شارپ #C را آماده کردم. انشاالله که این کد براتون مفید باشه.
کد خواندن XML document بر اساس نوع node در سی شارپ #C :
using System;
using System.Xml;
class MainClass
{
static void Main(string[] args)
{
int DecCounter=0, PICounter=0, DocCounter=0, CommentCounter=0, ElementCounter=0, AttributeCounter=0, TextCounter=0, WhitespaceCounter=0;
XmlTextReader reader = new XmlTextReader(@"C:\books.xml");
while (reader.Read())
{
XmlNodeType type = reader.NodeType;
switch (type) {
case XmlNodeType.XmlDeclaration:
DecCounter++;
break;
case XmlNodeType.ProcessingInstruction:
PICounter++;
break;
case XmlNodeType.DocumentType:
DocCounter++;
break;
case XmlNodeType.Comment:
CommentCounter++;
break;
case XmlNodeType.Element:
ElementCounter++;
if (reader.HasAttributes)
AttributeCounter += reader.AttributeCount;
break;
case XmlNodeType.Text:
TextCounter++;
using System.Xml;
class MainClass
{
static void Main(string[] args)
{
int DecCounter=0, PICounter=0, DocCounter=0, CommentCounter=0, ElementCounter=0, AttributeCounter=0, TextCounter=0, WhitespaceCounter=0;
XmlTextReader reader = new XmlTextReader(@"C:\books.xml");
while (reader.Read())
{
XmlNodeType type = reader.NodeType;
switch (type) {
case XmlNodeType.XmlDeclaration:
DecCounter++;
break;
case XmlNodeType.ProcessingInstruction:
PICounter++;
break;
case XmlNodeType.DocumentType:
DocCounter++;
break;
case XmlNodeType.Comment:
CommentCounter++;
break;
case XmlNodeType.Element:
ElementCounter++;
if (reader.HasAttributes)
AttributeCounter += reader.AttributeCount;
break;
case XmlNodeType.Text:
TextCounter++;