最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net(C#) Xml操作(增刪改查)練習

 更新時間:2009年01月30日 18:34:06   作者:  
web.config配置 前后臺文件等代碼
web.config配置:
復制代碼 代碼如下:

<appSettings>
<add key="xmlFile" value="xml/class.xml"/>
</appSettings>
<appSettings>
<add key="xmlFile" value="xml/class.xml"/>
</appSettings>

前臺:
復制代碼 代碼如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="test_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>C#操作Xml(增刪改查)練習</title>
</head>
<body>
<form id="form1" runat="server">
<div id="showXml" runat="server">
顯示Xml文檔
</div>
<div style="background-color:Green;color:Yellow;" style="background-color:Green;color:Yellow;">為html控件綁定服務器控件的兩個要點:<br />
1.onserverclick="serverMethod"這里只寫方法名.<br />
2.后臺代碼,必須是<br />
protected void XmlAdd(object sender, EventArgs e){}<br />
注意兩個參數(shù)及保護級.
</div>
<input id="btnAdd" type="button" value="add" runat="server" onserverclick="XmlAdd" />
<input id="btnDelete" type="button" value="delete" runat="server" onserverclick="XmlDelete" />
<input id="btnUpdate" type="button" value="update" runat="server" onserverclick="XmlUpdate" />
<input id="btnQuery" type="button" value="query" runat="server" onserverclick="XmlQuery" />
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="test_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>C#操作Xml(增刪改查)練習</title>
</head>
<body>
<form id="form1" runat="server">
<div id="showXml" runat="server">
顯示Xml文檔
</div>
<div style="background-color:Green;color:Yellow;" style="background-color:Green;color:Yellow;">為html控件綁定服務器控件的兩個要點:<br />
1.onserverclick="serverMethod"這里只寫方法名.<br />
2.后臺代碼,必須是<br />
protected void XmlAdd(object sender, EventArgs e){}<br />
注意兩個參數(shù)及保護級.
</div>
<input id="btnAdd" type="button" value="add" runat="server" onserverclick="XmlAdd" />
<input id="btnDelete" type="button" value="delete" runat="server" onserverclick="XmlDelete" />
<input id="btnUpdate" type="button" value="update" runat="server" onserverclick="XmlUpdate" />
<input id="btnQuery" type="button" value="query" runat="server" onserverclick="XmlQuery" />
</form>
</body>
</html>

后臺:
復制代碼 代碼如下:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class test_Default : System.Web.UI.Page
{
string xmlFile = System.Configuration.ConfigurationManager.AppSettings["xmlFile"];
XmlDocument XmlDoc = new XmlDocument();
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
private void Bind()
{
XmlDoc.Load(Server.MapPath("../" + xmlFile));//向上一級
this.showXml.InnerHtml = System.Web.HttpUtility.HtmlEncode(XmlDoc.InnerXml);
}
protected void XmlAdd(object sender, EventArgs e)
{
XmlNode objRootNode = XmlDoc.SelectSingleNode("http://Root"); //聲明XmlNode對象
XmlElement objChildNode = XmlDoc.CreateElement("Student"); //創(chuàng)建XmlElement對象
objChildNode.SetAttribute("id", "1");
objRootNode.AppendChild(objChildNode);
//
XmlElement objElement = XmlDoc.CreateElement("Name");//???結點和元素的區(qū)別?方法都一樣.
objElement.InnerText = "tree1";
objChildNode.AppendChild(objElement);
//保存
XmlDoc.Save(Server.MapPath("../" + xmlFile));
}
protected void XmlDelete(object sender, EventArgs e)
{
string Node = "http://Root/Student[Name='tree1']";//Xml是嚴格區(qū)分大小寫的.
XmlDoc.SelectSingleNode(Node).ParentNode.RemoveChild(XmlDoc.SelectSingleNode(Node));
//保存
XmlDoc.Save(Server.MapPath("../" + xmlFile));
}
protected void XmlUpdate(object sender, EventArgs e)
{
//XmlDoc.SelectSingleNode("http://Root/Student[Name='tree1']/Name").InnerText = "tree2";
XmlDoc.SelectSingleNode("http://Root/Student[Name='tree1']").Attributes["id"].Value = "001";
//保存
XmlDoc.Save(Server.MapPath("../" + xmlFile));
}
protected void XmlQuery(object sender, EventArgs e)
{
XmlNodeList NodeList = XmlDoc.SelectNodes("http://Root/Student");//查詢全部的student節(jié)點
//循環(huán)遍歷節(jié)點,查詢是否存在該節(jié)點
for (int i = 0; i < NodeList.Count; i++)
{
Response.Write(NodeList[i].ChildNodes[0].InnerText);
}
//查詢單個節(jié)點,//表示全部匹配的元素./表示以此為根的子元素.javascript下的查詢也是一樣.
string XmlPathNode = "http://Root/Student[Name='rock']/Photo";
Response.Write(XmlDoc.SelectSingleNode(XmlPathNode).InnerText);
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class test_Default : System.Web.UI.Page
{
string xmlFile = System.Configuration.ConfigurationManager.AppSettings["xmlFile"];
XmlDocument XmlDoc = new XmlDocument();
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
private void Bind()
{
XmlDoc.Load(Server.MapPath("../" + xmlFile));//向上一級
this.showXml.InnerHtml = System.Web.HttpUtility.HtmlEncode(XmlDoc.InnerXml);
}
protected void XmlAdd(object sender, EventArgs e)
{
XmlNode objRootNode = XmlDoc.SelectSingleNode("http://Root"); //聲明XmlNode對象
XmlElement objChildNode = XmlDoc.CreateElement("Student"); //創(chuàng)建XmlElement對象
objChildNode.SetAttribute("id", "1");
objRootNode.AppendChild(objChildNode);
//
XmlElement objElement = XmlDoc.CreateElement("Name");//???結點和元素的區(qū)別?方法都一樣.
objElement.InnerText = "tree1";
objChildNode.AppendChild(objElement);
//保存
XmlDoc.Save(Server.MapPath("../" + xmlFile));
}
protected void XmlDelete(object sender, EventArgs e)
{
string Node = "http://Root/Student[Name='tree1']";//Xml是嚴格區(qū)分大小寫的.
XmlDoc.SelectSingleNode(Node).ParentNode.RemoveChild(XmlDoc.SelectSingleNode(Node));
//保存
XmlDoc.Save(Server.MapPath("../" + xmlFile));
}
protected void XmlUpdate(object sender, EventArgs e)
{
//XmlDoc.SelectSingleNode("http://Root/Student[Name='tree1']/Name").InnerText = "tree2";
XmlDoc.SelectSingleNode("http://Root/Student[Name='tree1']").Attributes["id"].Value = "001";
//保存
XmlDoc.Save(Server.MapPath("../" + xmlFile));
}
protected void XmlQuery(object sender, EventArgs e)
{
XmlNodeList NodeList = XmlDoc.SelectNodes("http://Root/Student");//查詢全部的student節(jié)點
//循環(huán)遍歷節(jié)點,查詢是否存在該節(jié)點
for (int i = 0; i < NodeList.Count; i++)
{
Response.Write(NodeList[i].ChildNodes[0].InnerText);
}
//查詢單個節(jié)點,//表示全部匹配的元素./表示以此為根的子元素.javascript下的查詢也是一樣.
string XmlPathNode = "http://Root/Student[Name='rock']/Photo";
Response.Write(XmlDoc.SelectSingleNode(XmlPathNode).InnerText);
}
}

xml文件
復制代碼 代碼如下:

<?xml version="1.0" encoding="gb2312"?>
<Root>
<Student Admin="no">
<Name>rock</Name>
<NickName>rock1</NickName>
<Pwd>123</Pwd>
<Sex>男生</Sex>
<Birthday>1986-1-1</Birthday>
<Email>xymac@163.com</Email>
<QQ>123374355</QQ>
<Msn>loveplc@live.cn</Msn>
<Tel>13005129336</Tel>
<Homepage>http://m.fzitv.net</Homepage>
<Address>廣州</Address>
<Work>asp.net菜鳥</Work>
<Photo>images/rock.gif</Photo>
<Time>2008-3-18 10:15:29</Time>
</Student>
<Student Admin="yes">
<Name>tree</Name>
<NickName>宿舍老大</NickName>
<Pwd>51aspx</Pwd>
<Sex>男生</Sex>
<Birthday>
</Birthday>
<Email>support@tree.com</Email>
<QQ>
</QQ>
<Msn>
</Msn>
<Tel>
</Tel>
<Homepage>
</Homepage>
<Address>
</Address>
<Work>
</Work>
<Photo>
</Photo>
<Time>2008-3-26 11:39:57</Time>
</Student>
<Student>
<Name>tree2</Name>
</Student>
<Student id="001">
<Name>tree1</Name>
</Student>
</Root>

相關文章

  • 微信公眾平臺開發(fā)之發(fā)送圖文消息.Net代碼解析

    微信公眾平臺開發(fā)之發(fā)送圖文消息.Net代碼解析

    這篇文章主要為大家詳細解析了微信公眾平臺開發(fā)之發(fā)送圖文消息.Net代碼,感興趣的小伙伴們可以參考一下
    2016-06-06
  • .NET中字符串比較的最佳用法

    .NET中字符串比較的最佳用法

    本文詳細講解了.NET中字符串比較的最佳用法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-02-02
  • AJAX使用post發(fā)送數(shù)據(jù)xml格式接受數(shù)據(jù)

    AJAX使用post發(fā)送數(shù)據(jù)xml格式接受數(shù)據(jù)

    AJAX使用post發(fā)送數(shù)據(jù)xml格式接受數(shù)據(jù),需要的朋友可以參考一下
    2013-03-03
  • 使用最小?WEB?API?實現(xiàn)文件上傳的Swagger支持

    使用最小?WEB?API?實現(xiàn)文件上傳的Swagger支持

    這篇文章主要介紹了使用最小?WEB?API?實現(xiàn)文件上傳Swagger支持,我們使用最小?WEB?API?實現(xiàn)文件上傳功能,雖然客戶端訪問是正常的,但是當打開?Swagger?頁面時,沒法使用?Swagger?頁面測試,下面就來一篇支持Swagger的,需要的小伙伴可以參考一下
    2022-02-02
  • 通過jmeter壓測surging的方法

    通過jmeter壓測surging的方法

    Jmeter是Apache開源的一個使用純Java編寫的壓力測試工具,它最初是為測試web應用程序而設計的,但后來擴展到了其他測試功能,這篇文章主要介紹了通過jmeter壓測surging的相關知識,需要的朋友可以參考下
    2022-07-07
  • .net使用自定義類屬性實例

    .net使用自定義類屬性實例

    這篇文章主要介紹了.net使用自定義類屬性實例,詳細講述了自定義類屬性的原理及實現(xiàn)方法,需要的朋友可以參考下
    2014-10-10
  • 網(wǎng)頁(aspx)與用戶控件(ascx)交互邏輯處理實現(xiàn)

    網(wǎng)頁(aspx)與用戶控件(ascx)交互邏輯處理實現(xiàn)

    為了以后好維護,把幾個頁面(ASPX)相同的部分抽取放在一個用戶控件(ASCX)上,現(xiàn)在把邏輯分享下,感興趣的各位可以參考下哈
    2013-03-03
  • Asp.Net Mvc2 增刪改查DEMO代碼

    Asp.Net Mvc2 增刪改查DEMO代碼

    接觸mvc也有一段時間了(2.0),也看到園子里很多人在學習,自己也在園子里面看過前輩們寫的博客,確實受益匪淺。本文寫的都是基礎中的基礎,僅供想學習MVC的新手們入門之作
    2012-10-10
  • .NET Core 微信小程序退款步驟——(統(tǒng)一退款)

    .NET Core 微信小程序退款步驟——(統(tǒng)一退款)

    這篇文章主要介紹了.NET Core 微信小程序退款步驟——(統(tǒng)一退款),本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-09-09
  • C# 定義常量 兩種實現(xiàn)方法

    C# 定義常量 兩種實現(xiàn)方法

    在C#中定義常量的方式有兩種,一種叫做靜態(tài)常量(Compile-time constant),另一種叫做動態(tài)常量(Runtime constant)
    2012-11-11

最新評論

鹤峰县| 织金县| 泰州市| 双鸭山市| 东宁县| 古浪县| 桂平市| 资源县| 磐安县| 弥渡县| 通河县| 海盐县| 清原| 万州区| 长春市| 城口县| 安泽县| 青冈县| 眉山市| 钦州市| 阿克陶县| 永城市| 缙云县| 壶关县| 象山县| 九台市| 阿坝| 台北县| 永嘉县| 天气| 花莲县| 那曲县| 顺义区| 油尖旺区| 福清市| 隆尧县| 长海县| 三都| 湾仔区| 稻城县| 蓬莱市|