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

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

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

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

前臺:
復(fù)制代碼 代碼如下:

<%@ 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(增刪改查)練習(xí)</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控件綁定服務(wù)器控件的兩個要點:<br />
1.onserverclick="serverMethod"這里只寫方法名.<br />
2.后臺代碼,必須是<br />
protected void XmlAdd(object sender, EventArgs e){}<br />
注意兩個參數(shù)及保護(hù)級.
</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(增刪改查)練習(xí)</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控件綁定服務(wù)器控件的兩個要點:<br />
1.onserverclick="serverMethod"這里只寫方法名.<br />
2.后臺代碼,必須是<br />
protected void XmlAdd(object sender, EventArgs e){}<br />
注意兩個參數(shù)及保護(hù)級.
</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>

后臺:
復(fù)制代碼 代碼如下:

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");//???結(jié)點和元素的區(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是嚴(yán)格區(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");//查詢?nèi)康膕tudent節(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");//???結(jié)點和元素的區(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是嚴(yán)格區(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");//查詢?nèi)康膕tudent節(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文件
復(fù)制代碼 代碼如下:

<?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://www.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>

相關(guān)文章

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

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

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

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

    本文詳細(xì)講解了.NET中字符串比較的最佳用法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    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)文件上傳功能,雖然客戶端訪問是正常的,但是當(dāng)打開?Swagger?頁面時,沒法使用?Swagger?頁面測試,下面就來一篇支持Swagger的,需要的小伙伴可以參考一下
    2022-02-02
  • 通過jmeter壓測surging的方法

    通過jmeter壓測surging的方法

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

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

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

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

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

    Asp.Net Mvc2 增刪改查DEMO代碼

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

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

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

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

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

最新評論

石林| 高雄市| 富锦市| 北辰区| 顺昌县| 道真| 武汉市| 疏附县| 扶余县| 高安市| 宣汉县| 噶尔县| 黄龙县| 房产| 上虞市| 湖口县| 华宁县| 卢氏县| 吴江市| 小金县| 无锡市| 扶余县| 昌宁县| 灵寿县| 诸城市| 观塘区| 潜山县| 信阳市| 陆河县| 伊通| 体育| 福安市| 原阳县| 乌鲁木齐市| 武宁县| 广东省| 汝南县| 通海县| 阆中市| 黄山市| 崇礼县|