今天小編給大家分享的是創(chuàng)建xml文件的代碼,很多人都不太了解,今天小編為了讓大家更加了解創(chuàng)建xml文件的方法,所以給大家總結(jié)了以下內(nèi)容,一起往下看吧。一定會(huì)有所收獲的哦。
/// <summary> /// 創(chuàng)建一個(gè)xml文件 /// </summary> /// <param name="fileName">文件名字</param> private void createXmlDoc(string fileName) { string row= System.Environment.NewLine; XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xde ;//表示 XML 聲明節(jié)點(diǎn):<?xml version='1.0'...?> xde = xmlDoc.CreateXmlDeclaration("1.0", "ISO-8859-1", null);//verson:1.0 encoding:utf-8 standalone:yes(表示獨(dú)立的,不依賴(lài)別的文件) xmlDoc.AppendChild(xde); XmlElement root = xmlDoc.CreateElement("BOOKS"); root.SetAttribute("name", "根級(jí)元素"); xmlDoc.AppendChild(root); XmlElement node1 = xmlDoc.CreateElement("BOOK"); root.AppendChild(node1); XmlElement node11 = xmlDoc.CreateElement("AUTHOR"); node11.InnerText = "XMROOM"; node1.AppendChild(node11); XmlElement node12 = xmlDoc.CreateElement("NAME"); node12.InnerText = "編程你最?lèi)?ài)"; node1.AppendChild(node12); XmlElement node13 = xmlDoc.CreateElement("TIME"); node13.InnerText = "2013-11-20"; node1.AppendChild(node13); XmlElement node14 = xmlDoc.CreateElement("COPYRIGHT"); node14.InnerText = "XMROOM"; node1.AppendChild(node14); string path = Server.MapPath("Xml\\") + fileName + ".xml"; if (File.Exists(path)) { File.Delete(path); } xmlDoc.Save(path); }
以上就是創(chuàng)建xml文件的代碼的簡(jiǎn)略介紹,當(dāng)然詳細(xì)使用上面的不同還得要大家自己使用過(guò)才領(lǐng)會(huì)。如果想了解更多,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道哦!
文章名稱(chēng):創(chuàng)建xml文件的代碼分享-創(chuàng)新互聯(lián)
網(wǎng)站網(wǎng)址:http://www.rwnh.cn/article24/dddoce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)站收錄、標(biāo)簽優(yōu)化、用戶體驗(yàn)、手機(jī)網(wǎng)站建設(shè)、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容