欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
C#在WINForm程序中創(chuàng )建XML文件
<?xml version="1.0" encoding="gb2312"?><FilesInformation> <version>1.0.1818.42821</version> <description>說(shuō)明</description> <FileItem FileName="name" FileVersion="sdf" FileLength="sdf" FileCreationTime="sd" /></FilesInformation>

string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;    

獲取和設置包含該應用程序的目錄的名稱(chēng)

File.Exists(path + XmlFileName) 

File.Exists是判斷文件是否存在,傳入參數為路徑+文件名

XmlDocument xmlDoc = new XmlDocument();    

這一句是創(chuàng )建一個(gè)XmlDocument對象

XmlDeclaration xmlSM = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);   

這一句是添加xml文件頭的聲明

xmlDoc.AppendChild(xmlSM); 

這一句是將創(chuàng )建的XmlDocument對象追加到xml文件聲明后面

XmlElement DeviceTree = xmlDoc.CreateElement("DeviceTree"); 

這一句為創(chuàng )建一個(gè)標簽名為DeviceTree的節點(diǎn)

DeviceTree.SetAttribute("name", "設備樹(shù)");

這一句設置節點(diǎn)的name屬性為設備樹(shù)

xmlDoc.AppendChild(DeviceTree);

這一句是將創(chuàng )建的節點(diǎn)添加到開(kāi)始創(chuàng )建的XmlDocument對象中

xmlDoc.Save(path + XmlFileName);

最后是保存創(chuàng )建好的xml文件

方法1:

private void button1_Click(object sender, EventArgs e) { XmlDocument xmlDoc = new XmlDocument(); //建立Xml的定義聲明 XmlDeclaration dec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); xmlDoc.AppendChild(dec); //創(chuàng )建根節點(diǎn) XmlElement root = xmlDoc.CreateElement("FilesInformation"); xmlDoc.AppendChild(root); XmlElement version = xmlDoc.CreateElement("version"); version.InnerText = "1.0.1818.42821"; root.AppendChild(version); XmlElement description = xmlDoc.CreateElement("description"); description.InnerText = "說(shuō)明"; root.AppendChild(description); XmlElement fileItem = xmlDoc.CreateElement("FileItem"); fileItem.SetAttribute("FileName", "name"); fileItem.SetAttribute("FileVersion", "xx"); fileItem.SetAttribute("FileLength", "xxx"); fileItem.SetAttribute("FileCreationTime", "xxxx"); root.AppendChild(fileItem); xmlDoc.Save("test.xml"); }

方法2:

XmlDocument xmldoc = new XmlDocument(); XmlText xmltext;
//聲明 XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", ""); xmlnode.InnerText += " encoding=\"GB2312\""; xmldoc.AppendChild(xmlnode);
//添加根節點(diǎn) XmlElement xmlelementroot = xmldoc.CreateElement("", "Config", ""); //根節點(diǎn)包含節點(diǎn)文本時(shí)會(huì )造成XML文檔結構的混亂 //xmltext = xmldoc.CreateTextNode("配置信息"); //xmlelementroot.AppendChild(xmltext); xmldoc.AppendChild(xmlelementroot);
//添加一個(gè)元素 XmlElement xmlelement1 = xmldoc.CreateElement("", "DTL", ""); xmltext = xmldoc.CreateTextNode("2010-10-25"); xmlelement1.AppendChild(xmltext); xmldoc.ChildNodes.Item(1).AppendChild(xmlelement1);
//添加另一個(gè)元素 XmlElement xmlelement2 = xmldoc.CreateElement("", "DTF", ""); xmltext = xmldoc.CreateTextNode("2011-02-10"); xmlelement2.AppendChild(xmltext); xmldoc.ChildNodes.Item(1).AppendChild(xmlelement2);
//保存                xmldoc.Save(Environment.CurrentDirectory+"\\111.xml");

方法3:

XmlTextWriter xmlwriter = new XmlTextWriter(getPath(), Encoding.Default); xmlwriter.Formatting = Formatting.Indented; xmlwriter.Indentation = 4;
xmlwriter.WriteStartDocument(); xmlwriter.WriteStartElement("", "Config", "");
xmlwriter.WriteStartElement("", "DTL", ""); xmlwriter.WriteString("2010-10-25"); xmlwriter.WriteEndElement();
xmlwriter.WriteStartElement("", "DTF", ""); xmlwriter.WriteString("2011-02-10"); xmlwriter.WriteEndElement();
xmlwriter.WriteEndElement(); xmlwriter.WriteEndDocument();
xmlwriter.Flush(); xmlwriter.Close();

上面代碼中的getPath()是自定義的一個(gè)獲取文件路徑加名稱(chēng)的方法,請根據自己實(shí)際情況修改!我一般設定為(Environment.CurrentDirectory+"\\111.xml")

總的來(lái)說(shuō)還是方法三比較容易理解,簡(jiǎn)單易用,也是我常用的方法!

希望對各位有所幫助!

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
在C#.net中怎么操作XML
C# 寫(xiě)入XML文檔三種方法詳細介紹
C#操作xml
C#使用XmlDocument操作XML進(jìn)行查詢(xún)、增加、修改、刪除、保存應用的實(shí)例(轉載)...
.net中XML的簡(jiǎn)單應用 - - CSDN技術(shù)中心
Unity3D研究院之使用 C#合成解析XML與JSON(四十一) | 雨松MOMO程序研究院
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久