日期:2008-07-28  浏览次数:20573 次

最后,大家来看一下最负责的一个页面,这个页面的作用就是用来建立新的XML数据。
manage.ASPx </P><P><%@ 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"%> </P><P><HTML>
<HEAD>
<script language="C#" runat="server"> </P><P>public void Button1_Click(object sender, System.EventArgs e)
{
//判断文件是否存在
if(File.Exists(Server.MapPath(TextBox1.Text +".XML")))
{
Response.Write("文件名已经存在,请重选文件名。");
Response.End() ; </P><P>}
else
{ </P><P>XMLNode currNode;
XMLDocument XMLdoc = new XMLDocument();
XMLdoc.Load(Server.MapPath("contents.XML")); </P><P>string InsStr="<topic><title>"+TextBox2.Text+"</title><href>main.ASPx?name="+TextBox1.Text+"</href></topic>";
XMLDocumentFragment docFrag = XMLdoc.CreateDocumentFragment();
docFrag.InnerXML = InsStr; </P><P>currNode = XMLdoc.DocumentElement;
currNode.InsertAfter(docFrag, currNode.LastChild);
//save the output to a file
XMLdoc.Save (Server.MapPath("contents.XML")); </P><P>//把TextBox5中的文件换成符合XML格式的内容。
string XMLfile =TextBox5.Text.Replace("&","&");
XMLfile = XMLfile.Replace("<","<");
XMLfile = XMLfile.Replace(">",">");
XMLfile = XMLfile.Replace( @"""""",""");
XMLfile = XMLfile.Replace("'","&apos;");
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=""; </P><P>} </P><P></P><P>
//向目录文件中写数据 </P><P>}
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: 101; LEFT: 110px; POSITION: absolute; TOP: 68px" runat="server" Height="25px" Width="65px">
文件名:
</ASP:label>
<ASP:textbox id=TextBox1 style="Z-INDEX: 102; LEFT: 255px; POSITION: absolute; TOP: 64px" runat="server" Height="33px" Width="178px" >
</ASP:textbox>
<ASP:label id=Label3 style="Z-INDEX: 103; LEFT: 108px; POSITION: absolute; TOP: 126px" runat="server" Height="36px" Width="86px">
文章名称:
</ASP:label>
<ASP:textbox id=TextBox2 style="Z-INDEX: 104; LEFT: 256px; POSITION: absolute; TOP: 114px" runat="server" Height="37px" Width="177px">
</ASP:textbox>
<ASP:label id=Label4 style="Z-INDEX: 105; LEFT: 114px; POSITION: absolute; TOP: 183px" runat="server" Height="31px" Width="89px">
作者:
</ASP:label>
<ASP:textbox id=TextBox3 style="Z-INDEX: 106; LEFT: 256px; POSIT