当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用asp.net和xml做的新闻更新系统(3)

ASP
ASP动态生成的javascript表单验证代码
将身份证从15位升级为18位的函数
ASP自定义函数,仿VBA中域函数DLookup
6行代码实现无组件上传
用VS2003调试ASP的方法和体会
ASP中存储过程调用的两种方式及比较
升级到2003后访问数据库发生8007007f错误的解决
ACCESS转化成SQL2000需要注意的几个问题
让ASP程序运行于非Windows平台
一些不长见的ASP调用存储过程的技巧
网站图片扫描类
一条sql 语句搞定数据库分页
在ASP中取得服务器网卡的MAC地址、DNS地址等网络信息
ASP中轻松实现变量名-值变换
用Xml2OleDb将XML文件插入到数据库
购物车中数据的存放方式
ASP数据库编程SQL常用技巧
在ASP中利用ADO显示Excel文件内容的函数
ASP+SQL Server之图象数据处理
在 Access 中使用“存储过程”

ASP 中的 用asp.net和xml做的新闻更新系统(3)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 157 ::
收藏到网摘: n/a

      
  作者:飞鹰 版权归www.aspcool.com所有,转载时请保留此信息。
  
  最后,大家来看一下最负责的一个页面,这个页面的作用就是用来建立新的xml数据。
  manage.aspx
  
  <%@ Import Namespace="System.Xml.Xsl" %>
  <%@ Import Namespace="System.Xml" %>
  <%@ Assembly Name="System.Xml" %>
  <%@ Import Namespace="System.IO" %>
  <%@ Page Language="C#" Debug="true" codepage="936"%>
  <%@ Import Namespace="System"%>
  
  <HTML>
   <HEAD>
   <script language="C#" runat="server">
  
  public void Button1_Click(object sender, System.EventArgs e)
   {
   //判断文件是否存在
   if(File.Exists(Server.MapPath(TextBox1.Text +".xml")))
   {
   Response.Write("文件名已经存在,请重选文件名。");
   Response.End() ;
  
   }
   else
   {
  
   XmlNode currNode;
   XmlDocument xmldoc = new XmlDocument();
   xmldoc.Load(Server.MapPath("contents.xml"));
  
   string InsStr="<topic><title>"+TextBox2.Text+"</title><href>main.aspx?name="+TextBox1.Text+"</href></topic>";
   XmlDocumentFragment docFrag = xmldoc.CreateDocumentFragment();
   docFrag.InnerXml = InsStr;
  
   currNode = xmldoc.DocumentElement;
   currNode.InsertAfter(docFrag, currNode.LastChild);
   //save the output to a file
   xmldoc.Save (Server.MapPath("contents.xml"));
  
   //把TextBox5中的文件换成符合xml格式的内容。
   string xmlfile =TextBox5.Text.Replace("&","&");
   xmlfile = xmlfile.Replace("<","<");
   xmlfile = xmlfile.Replace(">",">");
   xmlfile = xmlfile.Replace( @"""""",""");
   xmlfile = xmlfile.Replace("'","'");
   xmlfile = xmlfile.Replace ("\n","</paragraph><paragraph>");
   //把数据写入新建的xml文件中去。
   XmlDocument doc = new XmlDocument();
   doc.LoadXml ("<?xml version='1.0' encoding='GB2312'?><document><title>"+TextBox2.Text +"</title><abstract>"+TextBox4.Text +"</abstract><author>"+TextBox3.Text +"</author><content><paragraph>"+xmlfile+"</paragraph></content></document>");
   doc.Save (Server.MapPath(TextBox1.Text +".xml"));
   Response.Write("You hava input the article!");
   TextBox1.Text="";
   TextBox2.Text="";
   TextBox3.Text="";
   TextBox4.Text="";
   TextBox5.Text="";
  
   }
  
  
  
  
   //向目录文件中写数据
  
   }
   public void Button2_Click(object sender, System.EventArgs e)
   {}
   </script>
   <meta content="Internet Explorer 5.0" name=vs_targetSchema>
   <meta content="Microsoft Visual Studio 7.0" name=GENERATOR>
   <meta content=C# name=CODE_LANGUAGE>
   </HEAD>
   <body MS_POSITIONING="GridLayout">
   <form runat="server">
   <FONT face=宋体>
   <asp:label id=Label1 style="Z-INDEX: 100; LEFT: 230px; POSITION: absolute; TOP: 27px" runat="server" Height="28px" Width="156px">
   asp酷技术资讯网网站内容发布系统
   </asp:label>
   <asp:label id=Label2 style="Z-INDEX: "