using System;
using SystemXml; namespace ReadXML
{
class Class
{
static void Main( string[] args )
{
int ws =;
int pi =;
int dc =;
int cc =;
int ac =;
int et =;
int el =;
int xd =; XmlTextReader textReader = new XmlTextReader(
C:\\books xml ); while (textReader
Read())
{
XmlNodeType nType = textReaderNodeType; // 節點類型為XmlDeclaration
if (nType == XmlNodeTypeXmlDeclaration)
{
ConsoleWriteLine( Declaration: + textReader Name ToString());
xd = xd +;
}// 節點類型為Comment
if( nType == XmlNodeTypeComment)
{
ConsoleWriteLine( Comment: + textReader Name ToString());
cc = cc +;
}// 節點類型為Attribute
if( nType == XmlNodeTypeAttribute)
{
ConsoleWriteLine( Attribute: + textReader Name ToString());
ac = ac +;
}// 節點類型為Element
if ( nType == XmlNodeTypeElement)
{
ConsoleWriteLine( Element: + textReader Name ToString());
el = el +;
}// 節點類型為Entity
if ( nType == XmlNodeTypeEntity )
{
ConsoleWriteLine( Entity: + textReader Name ToString());
et = et +;
}// 節點類型為Process Instruction
if( nType == XmlNodeTypeProcessInstruction )
{
ConsoleWriteLine( Process Instruction: + textReader Name ToString());
pi = pi +;
}// 節點類型為DocumentType
if( nType == XmlNodeTypeDocumentType)
{
ConsoleWriteLine( DocumentType: + textReader Name ToString());
dc = dc +;
}// 節點類型為Whitespace
if ( nType == XmlNodeTypeWhitespace )
{
ConsoleWriteLine( WhiteSpace: + textReader Name ToString());
ws = ws +;
}
}// 在控制台中顯示每種類型的數目
ConsoleWriteLine( Total Comments: + cc ToString());
ConsoleWriteLine( Total Attributes: + ac ToString());
ConsoleWriteLine( Total Elements: + el ToString());
ConsoleWriteLine( Total Entity: + et ToString());
ConsoleWriteLine( Total Process Instructions: + pi ToString());
ConsoleWriteLine( Total Declaration: + xd ToString());
ConsoleWriteLine( Total DocumentType: + dc ToString());
ConsoleWriteLine( Total WhiteSpaces: + ws ToString());
}
}
}
以上
四
XmlWriter類包含了寫XML文檔所需的方法和屬性
首先
XmlTextWriter textWriter = New XmlTextWriter(在創建完對象後C:\\myXmFile xml null);
[
From:http://tw.wingwit.com/Article/program/net/201311/15478.html