using System;
using SystemXml; namespace WriteXML
{
class Class
{
static void Main( string[] args )
{
// 創建XmlTextWriter類的實例對象
XmlTextWriter textWriter = new XmlTextWriter(C:\\myXmFile xml null); // 開始寫過程
調用WriteStartDocument方法
textWriterWriteStartDocument(); // 寫入說明
textWriterWriteComment( First Comment XmlTextWriter Sample Example );
textWriterWriteComment( myXmlFile xml in root dir ); // 寫入一個元素
textWriterWriteStartElement( Name );
textWriterWriteString( Student );
textWriterWriteEndElement(); // 再寫入一個元素
textWriterWriteStartElement( Address );
textWriterWriteString( Colony );
textWriterWriteEndElement(); // 寫入字符
char [] ch = new char[];
ch[] = a ;
ch[] = r ;
ch[] = c ;
textWriterWriteStartElement( Char );
textWriterWriteChars(ch ch Length);
textWriterWriteEndElement(); // 寫文檔結束
調用WriteEndDocument方法
textWriterWriteEndDocument(); // 關閉textWriter
textWriterClose();
}
}
}
五
XmlDocument類的對象代表了一個XML文檔
下面的程序中我們用到了XmlDocument類對象的LoadXml方法
// 創建一個XmlDocument類的對象
XmlDocument doc = new XmlDocument();
docLoadXml(( Tommy Lex )); // 保存到文件中
docSave( C:\\student xml );
這裡
docSave(Console Out);
而在下面的程序中
XmlDocument doc = new XmlDocument();
// 創建一個XmlTextReader對象讀取XML數據
XmlTextReader reader = new XmlTextReader(c:\\books xml );
readerRead(); // 載入XmlTextReader類的對象
docLoad(reader);
// 將XML數據顯示在控制台中
docSave(Console Out);
六
XML技術作為
附錄
<?xml version=?>
<!This file represents a fragment of a book store inventory database >
<bookstore>
<book genre=autobiography publicationdate= ISBN= >
<title>The Autobiography of Benjamin Franklin</title>
<author>
<firstname>Benjamin</first name>
<lastname>Franklin</last name>
</author>
<price></price>
</book>
<book genre=novel publicationdate= ISBN= >
<title>The Confidence Man</title>
<author>
<firstname>Herman</first name>
<lastname>Melville</last name>
</author>
<price></price>
</book>
<book genre=philosophy publicationdate= ISBN= >
<title>The Gorgias</title>
<author>
<firstname>Sidas</first name>
<lastname>Plato</last name>
</author>
<price></price>
</book>
</bookstore>
[
From:http://tw.wingwit.com/Article/program/net/201311/15480.html