欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

.net 操作xml的簡單方法及說明

 更新時間:2013年06月08日 11:33:44   作者:  
.net 操作xml的簡單方法及說明,需要的朋友可以參考一下
復制代碼 代碼如下:

using System.Xml;
//初始化一個xml實例
XmlDocument xml=new XmlDocument();
//導入指定xml文件
xml.Load(path);
xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
//指定一個節(jié)點
XmlNode root=xml.SelectSingleNode("/root");
//獲取節(jié)點下所有直接子節(jié)點
XmlNodeList childlist=root.ChildNodes;
//判斷該節(jié)點下是否有子節(jié)點
root.HasChildNodes;
//獲取同名同級節(jié)點集合
XmlNodeList nodelist=xml.SelectNodes("/Root/News");
//生成一個新節(jié)點
XmlElement node=xml.CreateElement("News");
//將節(jié)點加到指定節(jié)點下,作為其子節(jié)點
root.AppendChild(node);
//將節(jié)點加到指定節(jié)點下某個子節(jié)點前
root.InsertBefore(node,root.ChildeNodes[i]);
//為指定節(jié)點的新建屬性并賦值
node.SetAttribute("id","11111");
//為指定節(jié)點添加子節(jié)點
root.AppendChild(node);
//獲取指定節(jié)點的指定屬性值
string id=node.Attributes["id"].Value;
//獲取指定節(jié)點中的文本
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"));
 

相關文章

最新評論