现在的位置: 首页 > 综合 > 正文

XML读写操作

2014年02月15日 ⁄ 综合 ⁄ 共 4793字 ⁄ 字号 评论关闭

这是一个写XML的例子,如果App_Data中没有NewBook.xml则创建一个,然后把下图中内容保存到NewBook.xml

1.xml文件

 

<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database  -->
<bookstore>
<book genre="autobiography">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>

 2.xmlReadWriteOperation.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="xmlReadWriteOperation.aspx.cs" Inherits="xmlReadWriteOperation" %>

<!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>XML读写综合例子</title>
</head>
<body bgcolor="buttonface">
    
<form id="form1" runat="server">
    
<div>
<table border=1>
<tr>
<td colspan="2" >
<b>Book Details:</b>
</td>
</tr>

<tr>
<td >
Genre:
</td>
<td>
<asp:TextBox ID="txtGenre" runat="server" >
</asp:TextBox>
</td>
</tr>

<tr>
<td >
Title:
</td>
<td>
<asp:TextBox ID="txtTitle" runat="server" >
</asp:TextBox>
</td>
</tr>

<tr>
<td>
First Name:
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server" >
</asp:TextBox>
</td>
</tr>

<tr>
<td>
Last Name:
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server" >
</asp:TextBox>
</td>
</tr>

<tr>
<td>
Price:
</td>
<td>
<asp:TextBox ID="txtPrice" runat="server">
</asp:TextBox>
</td>
</tr>

<tr>
<td colspan="2">
<asp:Button Text="Save" runat="server" ID="btnSave"  OnClick="btnSave_Click"/>
</td>
</tr>

<tr>
<td colspan="2">
<asp:Label runat="server" ID="lblResult"/>
</td>
</tr>
</table>
    
</div>
    
</form>
</body>
</html>

3.xmlReadWriteOperation.aspx.cs

 

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;
/// <summary>
/// 功能:搜集页面上信息存储到xml中 
/// 编码:邓古谚 flyin2006
/// 时间:2006.9.15
/// </summary>

public partial class xmlReadWriteOperation : System.Web.UI.Page
{
    
Page_Load()

    
包括读,写xml的操作的综合例子

    
函数功能:在某个XmlDocument上增加一个书节点

抱歉!评论已关闭.