xml加载失败,请问是什么原因

yzl3 2005-12-15 01:29:19
请问一下是什么原因呢?


<?xml version="1.0" encoding="utf-8" ?>

<bookstore>
<book>
<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>
<title>The Confidence Man</title>
<author>
<first_name>Herman</first_name>
<last_name>Meiville</last_name>
<price>11.00</price></author>
</book>
</bookstore>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;

namespace WebApplication3
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Response.Write("<center><b>使用XmlDataDocument类</b><br><br></center>");
try
{
//创建XmlDataDocument并加载books.xml
XmlDataDocument myXmlDataDocument=new XmlDataDocument();
myXmlDataDocument.Load(Server.MapPath("localhost/WebAppplication3/books.xml"));

IncreasePrice(myXmlDataDocument.DocumentElement);
//保存xml
myXmlDataDocument.Save(Server.MapPath("localhost/WebApplication3/updatebooks.xml"));
Response.Write("<a href='localhost/WebApplication3/books.xml'>初始的xml文件</a>");
Response.Write("<br><br><a href='localhost/WebApplication3/updatebooks.xml'>修改后的xml文件</a>");
}
catch
{
Response.Write("加载xml失败!");
}

}
public void IncreasePrice(XmlNode node)
{
if(node.Name=="price")
{
node=node.FirstChild;
Decimal price=Decimal.Parse(node.Value);
//将所有书价提高2%
String newprice=((Decimal)price*(new Decimal(1.02))).ToString("#.00");
node.Value=newprice;
}
node=node.FirstChild;
while(node!=null)
{
IncreasePrice(node);
node=node.NextSibling;
}
}





#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
...全文
751 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧