Asp.net|xml| News System
Here I use XML instead of data, write a news release system, I hope to be able to play a role, so that more people can understand these latest technologies. Here are a few of these files.
Contents.xml
Aspcool news!
Main.aspx?name=hello
Resolve a problem
main.aspx?name=test
This is a very simple XML file that is used to display a list of news.
Hello.xml
Aspcool news!
Test News
feiying
the Firet test
This file is used to display the content of the news, the meaning of each of the people to see it, I will not be here to say more.
Here is a list of the pages shown in the news listing.
news.aspx
<%@ Import namespace= "System"%>
<%@ Page language= "C #" debug= "true" codepage= "936"%>
<%@ Import namespace= "System.IO"%>
<%@ Assembly name= "System.Xml"%>
<%@ Import namespace= "System.Xml"%> ><%@ Import namespace= "SYSTEM.XML.XSL"%>
<br>
<%=xslt ()%>
The program is designed by .
This page completes the transformation from XML to HTML files through XSLT, and also gives me a further understanding of XSLT.
The following is a page showing the news content:
Main.aspx
<%@ Import namespace= "System"%>
<%@ Page language= "C #" debug= "true" codepage= "936"%>
<%@ Import namespace= "System.IO"%>
<%@ Assembly name= "System.Xml"%>
<%@ Import namespace= "System.Xml"%>
<%@ Import namespace= "SYSTEM.XML.XSL"%>
<br>
<%=XSLT ()%>
<a Href= "Http://www.webjx.com"www.webjx.com</a> Design-making </p>
</body>
This function is the same as above, I will not say more here.
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
<%@ 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)
{
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 ();
}
Else
{
XmlNode Currnode;
XmlDocument xmldoc = new XmlDocument ();
XmlDoc. Load (Server.MapPath ("Contents.xml"));
String insstr= "<topic> <title>" +textbox2.text+ "</title> Main.aspx?name= "+textbox1.text+" 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"));
Replace the file in TEXTBOX5 with XML-formatted content.
String XMLFile =textbox5.text.replace ("&", "&");
XMLFile = xmlfile. Replace ("A", "a");
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= "";
}
Write data to a catalog file
}
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>
runat= "Server" id= "Button1" name= Button1 "style=" z-index:112;