PDA

View Full Version : خواندن از فایل XML



fazel-d
پنج شنبه 21 خرداد 1388, 21:12 عصر
چگونه می توان این کار رو انجام داد؟

raziee
پنج شنبه 21 خرداد 1388, 21:34 عصر
کتاب :

Professional ASP.NET 2.0 XML

Published by

Wiley Publishing, Inc.

10475 Crosspoint Boulevard
Indianapolis, IN 46256

www.wiley.com

Copyright © 2006 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN-13: 978-0-7645-9677-3
ISBN-10: 0-7645-9677-2

کتاب خیلی خوبیه.
حتما به دردت میخوره.
کد زیر رو از رو اون برات کپی کردم



<%@ Page Language=”C#” %>
<%@ Import Namespace=”System.Xml” %>
<script runat=”server”>
void Page_Load(object sender, EventArgs e)
{
//Location of XML file
string xmlFilePath = @”C:\Data\Employees.xml”;
try
{
//Get reference to the XmlReader object
using (XmlReader reader = XmlReader.Create(xmlFilePath))
{
string result;
while (reader.Read())
{
//Process only the elements
if (reader.NodeType == XmlNodeType.Element)
{
//Reset the variable for a new element
result = “”;
for (int count = 1;count <= reader.Depth; count++)
{
result += “===”;
}
result += “=> “ + reader.Name + “<br/>”;
lblResult.Text += result;
}
}
}
}
catch(Exception ex)
{
lblResult.Text = “An Exception occurred: “ + ex.Message;
}
}
</script>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Reading an XML File using XmlReader</title>
</head>
<body>
<form id=”form1” runat=”server”>
<div>
<asp:label id=”lblResult” runat=”server” />
</div>
</form>
</body>
</html>