<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>fatkun&#039;s blog &#187; 遍历xml</title>
	<atom:link href="http://fatkun.com/tag/%e9%81%8d%e5%8e%86xml/feed" rel="self" type="application/rss+xml" />
	<link>http://fatkun.com</link>
	<description>又一个 WordPress 站点</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:21:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>信息管理实验5-ASP.NET操作XML</title>
		<link>http://fatkun.com/2009/09/%e4%bf%a1%e6%81%af%e7%ae%a1%e7%90%86%e5%ae%9e%e9%aa%8c5-asp-net%e6%93%8d%e4%bd%9cxml.html</link>
		<comments>http://fatkun.com/2009/09/%e4%bf%a1%e6%81%af%e7%ae%a1%e7%90%86%e5%ae%9e%e9%aa%8c5-asp-net%e6%93%8d%e4%bd%9cxml.html#comments</comments>
		<pubDate>Wed, 30 Sep 2009 08:49:49 +0000</pubDate>
		<dc:creator>fatkun</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[XmlDocument]]></category>
		<category><![CDATA[信息管理实验]]></category>
		<category><![CDATA[遍历xml]]></category>

		<guid isPermaLink="false">http://fatkun.com/?p=26</guid>
		<description><![CDATA[1：实验目的，实验要求（自己写） 2：实验步骤： 一：Xml是实现病历共享的另外一种较好的方式。C#通过System.Xml空间下的一系列类来处理XML文档，如何使用这些类呢？ 在应用程序的头部添加： using System.Xml 二：新建patient.xml文档 &#60;?xml version="1.0" encoding="gb2312"?&#62; &#60;patientsmaterial&#62; &#60;/patientsmaterial&#62; ... 1：实验目的，实验要求（自己写） 2：实验步骤： 一：Xml是实现病历共享的另外一种较好的方式。C#通过System.Xml空间下的一系列类来处理XML文档，如何使用这些类呢？ 在应用程序的头部添加： using System.Xml 二：新建patient.xml文档 &#60;?xml version="1.0" encoding="gb2312"?&#62; &#60;patientsmaterial&#62; &#60;/patientsmaterial&#62; 三：创建ASP.NET应用程序，并在窗体上添加两个BUTTON按钮，5个TextBox，如图： 给出代码： Default.aspx &#60;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&#62; &#60;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&#62; &#60;html xmlns="http://www.w3.org/1999/xhtml" &#62; &#60;head runat="server"&#62; &#60;title&#62;无标题页&#60;/title&#62; &#60;/head&#62; &#60;body&#62; &#60;form id="form1" runat="server"&#62; &#60;div&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><img onload="ResizeImage(this,620)" src="http://fatkun.com/upload/2009/9/200909300056007868.jpg" alt="" title=""/><br />
1：实验目的，实验要求（自己写）<br />
2：实验步骤：<br />
一：Xml是实现病历共享的另外一种较好的方式。C#通过System.Xml空间下的一系列类来处理XML文档，如何使用这些类呢？<br />
在应用程序的头部添加：<br />
using System.Xml<br />
二：新建patient.xml文档</p>
<pre class="xml">
&lt;?xml version="1.0" encoding="gb2312"?&gt;
&lt;patientsmaterial&gt;
&lt;/patientsmaterial&gt;
...

<span id="more-26"></span>
1：实验目的，实验要求（自己写）
2：实验步骤：
一：Xml是实现病历共享的另外一种较好的方式。C#通过System.Xml空间下的一系列类来处理XML文档，如何使用这些类呢？
在应用程序的头部添加：
using System.Xml
二：新建patient.xml文档
<pre class="xml">
&lt;?xml version="1.0" encoding="gb2312"?&gt;
&lt;patientsmaterial&gt;
&lt;/patientsmaterial&gt;
</pre>
<p>三：创建ASP.NET应用程序，并在窗体上添加两个BUTTON按钮，5个TextBox，如图：<br />
<img onload="ResizeImage(this,620)" src="http://fatkun.com/upload/2009/9/200909300056007868.jpg" alt="" title=""/><br />
给出代码：<br />
Default.aspx</p>
<pre class="html">
&lt;%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
&lt;head runat="server"&gt;
&lt;title&gt;无标题页&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form id="form1" runat="server"&gt;
&lt;div&gt;
ID:&lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
姓名:&lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
性别:&lt;asp:TextBox ID="TextBox3" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
E-mail:&lt;asp:TextBox ID="TextBox4" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
地址:&lt;asp:TextBox ID="TextBox5" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;br /&gt;
&lt;br /&gt;
&nbsp;&lt;asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="输出所有节点(Button1)" /&gt;
&lt;asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="添加一个节点(Button2)" /&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Default.aspx.cs</p>
<pre class="c#">
using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page
{
//注意修改为自己patient.xml文件的路径
string filePath = "C:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2005\\WebSites\\WebSite5\\patient.xml";
protected void Page_Load(object sender, EventArgs e)
{
}
//输出所有节点
public void getAllElements() {
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
XmlNodeList nodeList = xmlDoc.SelectNodes("/patientsmaterial/patient");
Response.Write("所有节点:<br/>");
for (int i = 0; i < nodeList.Count; i++)
{
Response.Write("ID："+nodeList.Item(i).Attributes["ID"].Value);//输出ID
Response.Write("<br/>");
for (int j = 0; j < nodeList.Item(i).ChildNodes.Count; j++)
{
Response.Write(nodeList.Item(i).ChildNodes[j].Name + "：");
Response.Write(nodeList.Item(i).ChildNodes[j].InnerText);
Response.Write("<br/>");
}
Response.Write("<br/>");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
getAllElements();
}
protected void Button2_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
//查找
<patientsmaterial>
XmlNode root = xmlDoc.SelectSingleNode("patientsmaterial");
//创建patient节点
XmlElement xe1 = xmlDoc.CreateElement("patient");
//设置节点ID属性
xe1.SetAttribute("ID", TextBox1.Text.Trim());
XmlElement xesub1 = xmlDoc.CreateElement("name");
//设置文本节点
xesub1.InnerText = TextBox2.Text.Trim();
//添加到patient节点去
xe1.AppendChild(xesub1);
XmlElement xesub2 = xmlDoc.CreateElement("sex");
xesub2.InnerText = TextBox3.Text.Trim();
xe1.AppendChild(xesub2);
XmlElement xesub3 = xmlDoc.CreateElement("email");
xesub3.InnerText = TextBox4.Text.Trim();
xe1.AppendChild(xesub3);
XmlElement xesub4 = xmlDoc.CreateElement("address");
xesub4.InnerText = TextBox5.Text.Trim();
xe1.AppendChild(xesub4);
//添加到patientsmaterial节点
root.AppendChild(xe1);
xmlDoc.Save(filePath);
getAllElements();
}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://fatkun.com/2009/09/%e4%bf%a1%e6%81%af%e7%ae%a1%e7%90%86%e5%ae%9e%e9%aa%8c5-asp-net%e6%93%8d%e4%bd%9cxml.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

