日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

基于.net3.5以上XML操作.

發布時間:2025/7/14 asp.net 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于.net3.5以上XML操作. 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

//創建xml

View Code 1 View Code 2 [TestClass] 3 public class UnitTest1 4 { 5 static string xmlPath = "app.xml"; 6 7 [TestMethod] 8 public void CreateXML() 9 { 10 XNamespace ns = "http://www.so12.com/App";//命名空間 11 XDocument doc = new XDocument(new XDeclaration("1.0","utf-8","yes"), 12 new XComment("This is a commnet.Just input."), 13 new XElement(ns+"APP", 14 new XElement("DataBase", 15 new XElement("server","192.168.1.100",new XAttribute("desc","connning address")), 16 new XElement("baseName","report",new XAttribute("desc","database name")), 17 new XElement("loginName","sa",new XAttribute("desc","database login name")), 18 new XElement("loginPwd","sa",new XAttribute("desc","database login password"))), 19 new XElement("Software", 20 new XElement("output","C:\\Output\\"), 21 new XElement("input","C:\\Input\\"), 22 new XElement("import","C:\\Import\\")) 23 )); 24 doc.Save(xmlPath,SaveOptions.None); 25 } 26 }

?

//查詢,修改,添加 XML

View Code 1 XElement xe = XElement.Load(xmlPath); 2 // XElement xe=XElement.Parse("字符串XML"); 3 IEnumerable<XElement> list = xe.Descendants("server"); 4 //list.ToList()[0].Value 取值 5 System.Diagnostics.Trace.WriteLine(list.ToList()[0].Value); 6 7 //添加 8 IEnumerable<XElement> list = xe.Descendants("DataBase"); 9 list.ToList()[0].Add(new XElement("descption", "new new node")); 10 11 //更改 12 IEnumerable<XElement> list = xe.Descendants("descption"); 13 list.ToList()[0].SetValue("next again!");

?//刪除XML

View Code 1 IEnumerable<XElement> list = xe.Descendants("descption"); 2 list.ToList()[0].Remove();

?

轉載于:https://www.cnblogs.com/xmyy/articles/3053986.html

總結

以上是生活随笔為你收集整理的基于.net3.5以上XML操作.的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。