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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ASP.net Xml: ASP.net操作Xml

發布時間:2025/3/21 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.net Xml: ASP.net操作Xml 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?專題圖編號:ylbtechASPnetXml100010010

?

?

XML課件PPT【在線PPT課件倡導者-ylb】

?

  ?http://wenku.baidu.com/view/bfac3ebe1a37f111f1855bc2.html

?

1,功能描述

?  這是一個基于.net操作Xml的案例示例,對Vote.xml文檔的CRUD(增讀改刪)操作。本配有PPT課件供大家參考學習。

?

2,技術與環境

?

操作系統:

windows

開發語言:

C#

開發框架:

?

數據庫:

開發軟件:

Microsoft Visual Studio 2010

開發技術:

?ASP.net+Xml

課程總策劃:

yuanbo

成員:

null

個人主頁:

http://www.cnblogs.com/ylbtech/

科研團隊:

ylbtech

教研團隊:

ylbtech

?

3,/Vote.xml
<?xml version="1.0" encoding="utf-8"?> <vote><item belong="三國演義"><id>1</id><name>曉梅</name><number>60</number></item><item belong="西游記"><id>2</id><name>小駱</name><number>34</number></item><item belong="天涯"><id>3</id><name>莫離</name><number>110</number></item> </vote>

?

4,/App_Code/VoteInfo.cs
using System;/// <summary> ///Vote 的摘要說明 /// </summary> public class VoteInfo {// 1, Attributes/// <summary>/// 圖書名稱/// </summary>string _belong;/// <summary>/// 編號/// </summary>string _id;/// <summary>/// 作者/// </summary>string _name;/// <summary>/// 書本數量/// </summary>string _number;// 2, Structpublic VoteInfo(string belong, string id,string name, string number){this._belong = belong;this._id = id;this._name = name;this._number = number;}public VoteInfo(){}//封裝字段public string Belong{get { return _belong; }set { _belong = value; }}public string Id{get { return _id; }set { _id = value; }}public string Name{get { return _name; }set { _name = value; }}public string Number{get { return _number; }set { _number = value; }} }

?

5,/DemoXml.aspx.cs?ylb_tip: 這兒是.net對Xml操作的核心代碼區,請認真看,一定要把PPT課件看完,對根節點和節點要理解透

?

using System;using System.Xml; public partial class DemoXML : System.Web.UI.Page {/// <summary>/// ylb:1, 遍歷xml文檔/// </summary>private void BianLi(){ //提取xml文檔XmlDocument xd = new XmlDocument();xd.Load(Server.MapPath("Vote.xml"));//獲取根節點XmlNode root = xd.DocumentElement;//獲取節點列表XmlNodeList items = root.ChildNodes;//遍歷item項Response.Write("<pre>");foreach (XmlNode item in items){ //輸出屬性Response.Write(item.Attributes["belong"].Name+"="+item.Attributes["belong"].InnerText+"\t");//輸出子節點foreach (XmlNode p in item){Response.Write(p.Name+"="+p.InnerText+"\t");}Response.Write("\n");}Response.Write("</pre>");}/// <summary>/// ylb:2, 添加/// </summary>/// <param name="item"></param>private void Add(VoteInfo item){ //提取xml文檔XmlDocument xd = new XmlDocument();xd.Load(Server.MapPath("Vote.xml"));//獲取根節點XmlNode root = xd.DocumentElement;//創建元素XmlElement newItem = xd.CreateElement("item");XmlElement newID = xd.CreateElement("id");XmlElement newName = xd.CreateElement("name");XmlElement newNumber = xd.CreateElement("number");//配參newItem.SetAttribute("belong", item.Belong); //設置屬性 newID.InnerText = item.Id; //設置內容newName.InnerText = item.Name;newNumber.InnerText = item.Number;//裝配,實現其組織結構 root.AppendChild(newItem);newItem.AppendChild(newID);newItem.AppendChild(newName);newItem.AppendChild(newNumber);//保存xml文檔xd.Save(Server.MapPath("Vote.xml"));}/// <summary>/// ylb:3, 修改一項/// </summary>/// <param name="vote"></param>private void Update(VoteInfo vote){//提取xml文檔XmlDocument xd = new XmlDocument();xd.Load(Server.MapPath("Vote.xml"));//獲取根節點XmlNode root = xd.DocumentElement;//獲取節點類表XmlNodeList items = root.ChildNodes;//循環節點foreach (XmlNode item in items){//再循環節點foreach (XmlNode p in item){if (p.Name == "id" && p.InnerText == vote.Id){//則修改這一項//重設belong的值item.Attributes["belong"].InnerText = vote.Belong;//((XmlElement)item).SetAttribute("belong", vote.Belong);//給該節點(id)下的節點賦值p.NextSibling.InnerText = vote.Name;p.NextSibling.NextSibling.InnerText = vote.Number;}}}//保存xml文檔xd.Save(Server.MapPath("Vote.xml"));}/// <summary>/// ylb:4, 刪除一項/// </summary>/// <param name="id"></param>private void Delete(string id){ //提取xml文檔XmlDocument xd = new XmlDocument();xd.Load(Server.MapPath("vote.xml"));//獲取根節點XmlNode root = xd.DocumentElement;//獲取節點列表XmlNodeList items = root.ChildNodes;//循環節點foreach (XmlNode item in items){foreach (XmlNode p in item){if (p.Name == "id" && p.InnerText == id){ //移除該項 root.RemoveChild(item); }}}//保存xml文檔xd.Save(Server.MapPath("Vote.xml"));}protected void Page_Load(object sender, EventArgs e){//調用展示//ylb: 2,VoteInfo item = new VoteInfo("袁博自傳", "4", "ylb", "100");//Add(item);//ylb: 3, 根據id=3,修改 belong="天涯" name="莫離",number=110VoteInfo item2 = new VoteInfo("天涯", "3", "莫離", "110");//Update(item2);//ylb: 4, 刪除id=4的項Delete("3");//ylb: 1, 遍歷Xml文檔//BianLi(); } }

?

6,示例|講解案例下載

博客園講解:

?????? http://ylbtech.cnblogs.com/

百度文庫開發文檔:

?????? http://passport.baidu.com/?business&aid=6&un=ylbtech#7

谷歌開源代碼下載:

????? ?http://code.google.com/p/ylbtechaspnet/downloads/list

請單擊“ylbtechXml100010010”

?

作者:ylbtech
出處:http://ylbtech.cnblogs.com/
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接,否則保留追究法律責任的權利。

?

總結

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

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