A news system made with asp.net and XML

Source: Internet
Author: User
Tags abstract tostring xsl xslt visual studio
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 technology. Here are a few of these files.


Contents.xml
<?xml version= "1.0" encoding= "GB2312"?>
<topiclist type= "Aspcool News" >
<topic>
<title>aspcool news!</title>
</topic>
<topic>
<title>resolve a problem</title>
</topic>
</topiclist>

This is a very simple XML file that is used to display a list of news.


Hello.xml
<?xml version= "1.0" encoding= "GB2312"?>
<document>
<title>aspcool news!</title>
<abstract>test news</abstract>
<author>feiying</author>
<content>
<paragraph>the Firet test</paragraph>
</content>
</document>

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"%>
<title>
</title>
<script language= "C #" runat= "Server" >
public string XSLT ()
{
StringWriter writer = new StringWriter ();
Loading XML objects
XmlDocument xmldoc= New XmlDocument ();
XmlDoc. Load (Server.MapPath ("Contents.xml"));
Mount an XSL object
XslTransform Xsldoc = new XslTransform ();
Xsldoc. Load (Server.MapPath ("news.xsl"));
Translating XML into HTML pages
Documentnavigator nav= New Documentnavigator (xmldoc);
Xsldoc. Transform (Nav,null,writer);
return writer. ToString ();
}
</script>
<body>
&LT;%=XSLT ()%>
<p align= "center" >

The program is made by <a href= "www.aspcool.comhttp://www.aspcool.com" >www.aspcool.com</a> design.


</p>
</body>

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"%>
<title>
</title>
<script language= "C #" runat= "Server" >
public string XSLT ()
{
StringWriter writer = new StringWriter ();
XmlDocument xmldoc= New XmlDocument ();
XmlDoc. Load (Server.MapPath (request["name"] + ". xml"));
XslTransform Xsldoc = new XslTransform ();
Xsldoc. Load (Server.MapPath ("main.xsl"));
Documentnavigator nav= New Documentnavigator (xmldoc);
Xsldoc. Transform (Nav,null,writer);
return writer. ToString ();
}
</script>
<body>
&LT;%=XSLT ()%>
<p align= "Center" > The program was made by <a href= "www.aspcool.comhttp://www.aspcool.com" >www.aspcool.com</a> design. </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 ("<", "<");
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>


<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= ">"
<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.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.