首页
最近更新
热门教程
ASP.NET
开发语言
开发环境
AJax教程
控件开发
统计报表
数据库
Web服务
安装部署
HTML教程
Javascript
XML教程
Community Server
NHibernate
书籍推荐
常用工具
实用代码
教程全文搜索
首页
>>
ASP.NET
ASP.NET访问XML的例子
添加人:
zhongguo
添加时间:2008-07-26 阅读次数:843
收藏此教程
protected
void
Page_Load(
object
sender, EventArgs e)
{
string
employeeID
=
""
;
string
xmlFilePath
=
Request.PhysicalApplicationPath
+
@"
\Employees.xml
"
;
try
{
using
(XmlReader reader
=
XmlReader.Create(xmlFilePath))
{
this
.mEmployeesLabel.Text
=
"
<b>Employees</b>
"
;
this
.mEmployeesLabel.Text
+=
"
<ul>
"
;
while
(reader.Read())
{
if
(reader.NodeType
==
XmlNodeType.Element)
{
if
(reader.Name
==
"
employee
"
)
{
employeeID
=
reader.GetAttribute(
"
id
"
);
}
if
(reader.Name
==
"
name
"
)
{
this
.mEmployeesLabel.Text
+=
"
<li>
"
+
"
Employee-
"
+
employeeID;
this
.mEmployeesLabel.Text
+=
"
<ul>
"
;
this
.mEmployeesLabel.Text
+=
"
<li>ID-
"
+
employeeID
+
"
</li>
"
;
}
if
(reader.Name
==
"
firstName
"
)
{
this
.mEmployeesLabel.Text
+=
"
<li>First Name-
"
+
reader.ReadString()
+
"
</li>
"
;
}
if
(reader.Name
==
"
lastName
"
)
{
this
.mEmployeesLabel.Text
+=
"
<li>Last Name-
"
+
reader.ReadString()
+
"
</li>
"
;
}
if
(reader.Name
==
"
city
"
)
{
this
.mEmployeesLabel.Text
+=
"
<li>City-
"
+
reader.ReadString()
+
"
</li>
"
;
}
if
(reader.Name
==
"
state
"
)
{
this
.mEmployeesLabel.Text
+=
"
<li>state-
"
+
reader.ReadString()
+
"
</li>
"
;
}
if
(reader.Name
==
"
zipCode
"
)
{
this
.mEmployeesLabel.Text
+=
"
<li>state-
"
+
reader.ReadElementContentAsInt()
+
"
</li>
"
;
}
}
else
if
(reader.NodeType
==
XmlNodeType.EndElement)
{
if
(reader.Name
==
"
employee
"
)
{
this
.mEmployeesLabel.Text
+=
"
</ul>
"
;
this
.mEmployeesLabel.Text
+=
"
</li>
"
;
}
}
}
this
.mEmployeesLabel.Text
+=
"
</ul>
"
;
}
}
catch
(Exception ex)
{
this
.mEmployeesLabel.Text
=
"
An Exception occured:
"
+
ex.Message;
}
}
共
1
页 第
1
页
上一页
1
下一页
相关的教程:
ASP.NET XML
收藏此教程
Currently.-0.05/5
-5
-4
-3
-2
-1
0
1
2
3
4
5
当前平均分:
3.1
(
10
次打分)
-5
-4
-3
-2
-1
0
1
2
3
4
5
推荐阅读
添加评论
评论主题
您的大名
您的评论
验证码
评论列表
ASP.NET论坛
|
网站帮助
|
加入收藏
知识库搜索:
用户信息
欢迎您,游客。
登录
|
注册
为什么要注册?
马上加入GotAspx,建立自己的知识库,与大家分享您的知识库,还可获得丰厚积分奖励!
本类热门
从零开始学ASP.NET(基础篇)
ASP.NET 2.0轻松实现数据库应用开发
ASP.NET 程序中常用的三十三种代码
GridView 72般绝技(一)
对初学者的建议:ASP.NET技术的学习顺序
单点登录在ASP.NET上的简单实现
ASP.NET数据库编程快速入门之技术慨述
ASP.NET 2.0中构造个性化网页
本类最新
介绍SubSonic【转】
ASP.NET访问XML的例子
WEB开发者版本级别
基于.NET2.0的System.Net.Mail发送邮件Demo
Asp.Net 文件操作基类(读取,删除,批量拷贝,批量删除,写入)
c#生成与 追加xml
一个复杂的Eval()绑定
将服务器上的一个.doc文档另存为到客户端