1.已知有一個XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?> |
1、往<bookstore>節點中插入一個<book>節點:
XmlDocument xmlDoc=new XmlDocument(); |
//================
結果為:
<?xml version="1.0" encoding="gb2312"?> |
2、修改節點:將genre屬性值為“李贊紅“的節點的genre值改為“update李贊紅”,將該節點的子節點<author>的文本修改為“亞勝”。
XmlNodeList nodeList=xmlDoc.SelectSingleNode("bookstore").ChildNodes;//獲取bookstore節點的所有子節點 |
<?xml version="1.0" encoding="gb2312"?> |
XmlNodeList xnl=xmlDoc.SelectSingleNode("bookstore").ChildNodes; |
if(xe.GetAttribute("genre")=="fantasy") |
| <?xml version="1.0" encoding="gb2312"?> <bookstore> <book ISBN="2-3631-4"> <title>Oberon's Legacy</title> <author>Corets, Eva</author> <price>5.95</price> </book> <book> </book> </bookstore> |
XmlNode xn=xmlDoc.SelectSingleNode("bookstore"); |

<%
@ Page language="c#" Codebehind="Main.aspx.cs" AutoEventWireup="false" Inherits="DsAndXML.OpXMLFile.Main" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Main</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Main" method="post" runat="server">
<FONT face="宋體">
<asp:DataGrid id="dgShow" style="Z-INDEX: 100; LEFT: 113px; POSITION: absolute; TOP: 32px" runat="server" Width="480px" Height="178px"></asp:DataGrid>
<asp:Label id="Label3" style="Z-INDEX: 111; LEFT: 187px; POSITION: absolute; TOP: 383px" runat="server" Width="120px" Height="21px">新郵件地址:</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 107; LEFT: 333px; POSITION: absolute; TOP: 274px" runat="server" Width="83px" Height="21px">郵件地址:</asp:Label>
<asp:Button id="btnAdd" style="Z-INDEX: 104; LEFT: 298px; POSITION: absolute; TOP: 324px" runat="server" Text="添加"></asp:Button>
<asp:Button id="btnDelete" style="Z-INDEX: 103; LEFT: 199px; POSITION: absolute; TOP: 324px" runat="server" Text="刪除"></asp:Button>
<asp:Button id="btnChange" style="Z-INDEX: 102; LEFT: 102px; POSITION: absolute; TOP: 382px" runat="server" Text="修改"></asp:Button>
<asp:Button id="btnQuery" style="Z-INDEX: 101; LEFT: 101px; POSITION: absolute; TOP: 324px" runat="server" Text="查詢"></asp:Button>
<asp:DropDownList id="ddlName" style="Z-INDEX: 105; LEFT: 210px; POSITION: absolute; TOP: 274px" runat="server" Width="95px" Height="78px"></asp:DropDownList>
<asp:Label id="Label1" style="Z-INDEX: 106; LEFT: 100px; POSITION: absolute; TOP: 274px" runat="server" Width="83px" Height="21px">姓名:</asp:Label>
<asp:Label id="lbEmail" style="Z-INDEX: 109; LEFT: 459px; POSITION: absolute; TOP: 274px" runat="server" Width="231px"></asp:Label>
<asp:TextBox id="tbNewMail" style="Z-INDEX: 110; LEFT: 330px; POSITION: absolute; TOP: 381px" runat="server" Width="208px" Height="26px"></asp:TextBox></FONT>
</form>
</body>
</HTML>
新聞熱點
疑難解答