News update system with asp.net and XML (3)
Last Update:2017-02-28
Source: Internet
Author: User
Asp.net|xml Finally, let's take a look at one of the most responsible pages, the role of which is to create new XML data.
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)
{
To determine whether a file exists
if (File.exists (Server.MapPath (TextBox1.Text + ". xml"))
{
Response.Write ("FileName already exists," please select the filename.) ");
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>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>//replaces the file in TEXTBOX5 with XML-formatted content.
String XMLFile =textbox5.text.replace ("&", "&");
XMLFile = xmlfile. Replace ("<", "<");
XMLFile = xmlfile. Replace (">", ">");
XMLFile = xmlfile. Replace (@ "" "" "", "" ");
XMLFile = xmlfile. Replace ("'", "" ");
XMLFile = xmlfile. Replace ("\ n", "</paragraph><paragraph>");
Writes the data to the newly created XML file.
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>
Write data to the directory file </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= Song Body >
<asp:label id=label1 style= "Z-INDEX:100; left:230px; Position:absolute; TOP:27PX "runat=" Server "height=" 28px "width=" 156px ">
ASP Cool technology Information Network website content Publishing system
</asp:label>
<asp:label id=label2 style= "Z-INDEX:101; left:110px; Position:absolute; top:68px "runat=" Server "height=" 25px "width=" 65px ">
Filename:
</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 ">
Article name:
</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 ">
Author:
</asp:label>
<asp:textbox id=textbox3 style= "z-index:106; left:256px; Position:absolute; TOP:183PX "runat=" Server "height=" 36px "width=" 179px ">
</asp:textbox>
<asp:label id=label5 style= "z-index:107; left:114px; Position:absolute; top:241px "runat=" Server "height=" 51px "width=" 81px ">
Summary:
</asp:label>
<asp:textbox id=textbox4 style= "z-index:108; left:256px; Position:absolute; top:245px "runat=" Server "height=" 36px "width=" 179px ">
</asp:textbox>
<asp:label id=label6 style= "z-index:109; left:116px; Position:absolute; top:315px "runat=" Server "height=" 36px "width=" 78px ">
Content:
</asp:label>
<asp:textbox id=textbox5 style= "z-index:110; left:259px; Position:absolute; TOP:303PX "runat=" Server "height=" 95px "width=" 252px "textmode=" MultiLine ">
</asp:textbox>
</FONT> </p><p><input id=button2 style= "z-index:113; left:343px; width:40px; Position:absolute; top:430px; height:24px "Type=button value= reset name=button2 runat=" Server "onserverclick=" button2_click "designtimedragdrop=" 59 " >
<br>
<br>
<div id=mess runat=server>
</div>
<br>
<input type= "button" value= "Submit" onserverclick= Button1_Click "runat=" Server "id=" Button1 "name=" Button1 "style=" z-index:112; left:268px; Position:absolute; top:430px ">
</form>
</body>
</HTML>
This program is tested through. NET Beta2 build 9148. Finish