天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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

web.config配置:
復(fù)制代碼 代碼如下:
<appSettings>
<add key="xmlFile" value="xml/class.xml"/>
</appSettings>
<appSettings>
<add key="xmlFile" value="xml/class.xml"/>
</appSettings>

前臺(tái):
復(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ù)器控件的兩個(gè)要點(diǎn):<br />
1.onserverclick="serverMethod"這里只寫方法名.<br />
2.后臺(tái)代碼,必須是<br />
protected void XmlAdd(object sender, EventArgs e){}<br />
注意兩個(gè)參數(shù)及保護(hù)級(jí).
</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ù)器控件的兩個(gè)要點(diǎn):<br />
1.onserverclick="serverMethod"這里只寫方法名.<br />
2.后臺(tái)代碼,必須是<br />
protected void XmlAdd(object sender, EventArgs e){}<br />
注意兩個(gè)參數(shù)及保護(hù)級(jí).
</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>

后臺(tái):
復(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));//向上一級(jí)
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é)點(diǎn)和元素的區(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é)點(diǎn)
//循環(huán)遍歷節(jié)點(diǎn),查詢是否存在該節(jié)點(diǎn)
for (int i = 0; i < NodeList.Count; i++)
{
Response.Write(NodeList[i].ChildNodes[0].InnerText);
}
//查詢單個(gè)節(jié)點(diǎn),//表示全部匹配的元素./表示以此為根的子元素.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));//向上一級(jí)
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é)點(diǎn)和元素的區(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é)點(diǎn)
//循環(huán)遍歷節(jié)點(diǎn),查詢是否存在該節(jié)點(diǎn)
for (int i = 0; i < NodeList.Count; i++)
{
Response.Write(NodeList[i].ChildNodes[0].InnerText);
}
//查詢單個(gè)節(jié)點(diǎn),//表示全部匹配的元素./表示以此為根的子元素.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>[email protected]</Email>
<QQ>123374355</QQ>
<Msn>[email protected]</Msn>
<Tel>13005129336</Tel>
<Homepage>http://www.jb51.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>[email protected]</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>

AspNet技術(shù)asp.net(C#) Xml操作(增刪改查)練習(xí),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 亚洲视频无码中字在线 | 国产99小视频| 粗大分开挺进内射 | 精品国产mmd在线观看 | 最近2018年手机中文字幕 | 欧美亚洲另类图片 | 婚后被调教当众高潮H喷水 回复术士勇者免费观看全集 | 青青草原在线新免费 | 精品手机在线1卡二卡3卡四卡 | 亚洲AV国产福利精品在现观看 | 暖暖视频 免费 高清 日本8 | 久久国产露脸老熟女熟69 | 内射少妇三洞齐开 | 伊人久久艹 | V8成品人视频 | 男人国产AV天堂WWW麻豆 | 小妇人电影免费完整观看2021 | 香港论理午夜电影网 | 久久精视频| 日韩高清特级特黄毛片 | 年轻的老师5理伦片 | 大桥未久与黑人中出视频 | 超碰在线观看 | 色尼姑久久超碰在线 | 午夜看片a福利在线观看 | 世界上第一个得抑郁症的人是谁 | 40分钟超爽大片黄 | 国产专区_爽死777 | 麻豆E奶女教师国产精品 | 午夜一个人在线观看完整版 | 一个人的视频在线观看免费观看 | 日本边添边摸边做边爱边 | 丰满的寡妇hd高清在线观看 | 日本学生VIDEOVIDEOS更新 日本性xxx | 神马影院在线eecss伦理片 | 精品国产福利一区二区在线 | 精品久久久久中文字幕加勒比东京热 | 最近日本免费观看MV免费 | 九九久久国产 | 偷窥美女3| 樱桃视频高清免费观看在线播放 |