C#中保存XML文件時加入頭部定義行

            XmlDocument doc = new XmlDocument();

            XmlDeclaration xmldecl;

            xmldecl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);            

            //Add the new node to the document.

            XmlElement root = doc.DocumentElement;

            doc.InsertBefore(xmldecl, root);   

            doc.AppendChild(doc.CreateElement("item", "urn:1"));

            doc.PreserveWhitespace = false;

         

            doc.Save("C:\\1.xml");

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章