溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

創(chuàng)建xml文件的代碼分享

發(fā)布時間:2020-04-16 09:29:18 來源:億速云 閱讀:270 作者:小新 欄目:編程語言

今天小編給大家分享的是創(chuàng)建xml文件的代碼,很多人都不太了解,今天小編為了讓大家更加了解創(chuàng)建xml文件的方法,所以給大家總結(jié)了以下內(nèi)容,一起往下看吧。一定會有所收獲的哦。

  /// <summary>
    /// 創(chuàng)建一個xml文件
    /// </summary>
    /// <param name="fileName">文件名字</param>
    private void createXmlDoc(string fileName)
    {
      string  row=  System.Environment.NewLine;  
        XmlDocument xmlDoc = new XmlDocument();
        XmlDeclaration xde  ;//表示 XML 聲明節(jié)點:<?xml version='1.0'...?>
        xde = xmlDoc.CreateXmlDeclaration("1.0", "ISO-8859-1", null);//verson:1.0 encoding:utf-8  standalone:yes(表示獨立的,不依賴別的文件)
        xmlDoc.AppendChild(xde);
        XmlElement root = xmlDoc.CreateElement("BOOKS");
        root.SetAttribute("name", "根級元素");
        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 = "編程你最愛";
        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文件的代碼的簡略介紹,當(dāng)然詳細(xì)使用上面的不同還得要大家自己使用過才領(lǐng)會。如果想了解更多,歡迎關(guān)注億速云行業(yè)資訊頻道哦!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI