.net 操作xml的簡(jiǎn)單方法及說(shuō)明
更新時(shí)間:2013年06月08日 11:33:44 作者:
.net 操作xml的簡(jiǎn)單方法及說(shuō)明,需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
using System.Xml;
//初始化一個(gè)xml實(shí)例
XmlDocument xml=new XmlDocument();
//導(dǎo)入指定xml文件
xml.Load(path);
xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
//指定一個(gè)節(jié)點(diǎn)
XmlNode root=xml.SelectSingleNode("/root");
//獲取節(jié)點(diǎn)下所有直接子節(jié)點(diǎn)
XmlNodeList childlist=root.ChildNodes;
//判斷該節(jié)點(diǎn)下是否有子節(jié)點(diǎn)
root.HasChildNodes;
//獲取同名同級(jí)節(jié)點(diǎn)集合
XmlNodeList nodelist=xml.SelectNodes("/Root/News");
//生成一個(gè)新節(jié)點(diǎn)
XmlElement node=xml.CreateElement("News");
//將節(jié)點(diǎn)加到指定節(jié)點(diǎn)下,作為其子節(jié)點(diǎn)
root.AppendChild(node);
//將節(jié)點(diǎn)加到指定節(jié)點(diǎn)下某個(gè)子節(jié)點(diǎn)前
root.InsertBefore(node,root.ChildeNodes[i]);
//為指定節(jié)點(diǎn)的新建屬性并賦值
node.SetAttribute("id","11111");
//為指定節(jié)點(diǎn)添加子節(jié)點(diǎn)
root.AppendChild(node);
//獲取指定節(jié)點(diǎn)的指定屬性值
string id=node.Attributes["id"].Value;
//獲取指定節(jié)點(diǎn)中的文本
string content=node.InnerText;
//保存XML文件
string path=Server.MapPath("~/file/bookstore.xml");
xml.Save(path);
//or use :xml.Save(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
相關(guān)文章
asp.net mvc實(shí)現(xiàn)簡(jiǎn)單的實(shí)時(shí)消息推送
這篇文章主要介紹了asp.net mvc實(shí)現(xiàn)簡(jiǎn)單的實(shí)時(shí)消息推送的相關(guān)資料,需要的朋友可以參考下2016-07-07
ASP.NET?Core中的Caching組件簡(jiǎn)介
這篇文章介紹了ASP.NET?Core中的Caching組件,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
ASP.NET Gridview與checkbox全選、全不選實(shí)現(xiàn)代碼
ASP.NET Gridview checkbox全選與全不選實(shí)現(xiàn)代碼,其實(shí)原理就是利用js來(lái)實(shí)現(xiàn)的,但需要簡(jiǎn)單的設(shè)置下回傳。2010-04-04
在.NET程序崩潰時(shí)自動(dòng)創(chuàng)建Dump的思路詳解
本文主要是介紹了如何在dotNet程序崩潰時(shí)自動(dòng)創(chuàng)建Dump,Windows上的方法對(duì)于.NET Freamwork和.NET Core版本都適用,.NET Core全平臺(tái)版本的話需要注意環(huán)境變量支持的.NET版本,對(duì).net程序崩潰自動(dòng)創(chuàng)建Dump相關(guān)知識(shí)感興趣的朋友一起看看吧2022-11-11

