<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ReadXmlEfficient" %>
Untitled Page
File: Default.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.Text;
using System.Xml;
public partial class ReadXmlEfficient : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string xmlFile = Server.MapPath("Data.xml");
XmlTextReader reader = new XmlTextReader(xmlFile);
StringBuilder str = new StringBuilder();
reader.ReadStartElement("DvdList");
while (reader.Read())
{
if ((reader.Name == "DVD") && (reader.NodeType == XmlNodeType.Element))
{
reader.ReadStartElement("DVD");
str.Append("");
str.Append(reader.ReadElementString("Title"));
str.Append("- ");
str.Append(reader.ReadElementString("Director"));
str.Append(" - ");
str.Append(String.Format("{0:C}",Decimal.Parse(reader.ReadElementString("Price"))));
str.Append("
");
}
}
reader.Close();
XmlText.Text = str.ToString();
}
}
File: Data.xml
title 1
directory 2
1
star 1
star 2
title 2
directory 2
2
star 3
star 4