当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  用asp.net和xml做的新闻更新系统

 用asp.net和xml做的新闻更新系统

点击次数:16 次 发布日期:2008-11-26 15:48:59 作者:源代码网
源代码网推荐      读了很多关于.net的文章,也看了许多关于xml的资料,我已经深深的被他们的魅力所吸引。在网上的论坛中,大家对于.net的讨论更加火热一些,而我们的同事从微软回来后告诉我,其实xml是一个比.net更好的东西。包括其中的xslt,其未来要远远比.net要好。
源代码网推荐  
源代码网推荐   其实争论谁好谁坏本身是没有多大意思的,因为.net本身已经和xml紧密的结合在一起了。这里我就用xml代替数据,写一个新闻发布系统,希望能够起到抛砖引玉的作用,使更多的人能够了解这些最新的技术。
源代码网推荐  
源代码网推荐   下面介绍这几个文件。
源代码网推荐  
源代码网推荐   contents.xml
源代码网推荐  
源代码网推荐  
源代码网推荐   <?xml version="1.0" encoding="GB2312"?>
源代码网推荐   <topiclist type="AspCool News">
源代码网推荐   <topic>
源代码网推荐   <title>aspcool news!</title>
源代码网推荐   <href>main.aspx?name=hello</href>
源代码网推荐   </topic>
源代码网推荐   <topic>
源代码网推荐   <title>Resolve a problem</title>
源代码网推荐   <href>main.aspx?name=test</href>
源代码网推荐   </topic>
源代码网推荐   </topiclist>
源代码网推荐  
源代码网推荐  
源代码网推荐   这是一个很简单的xml文件,它的作用是用来显示新闻的列表。
源代码网推荐  
源代码网推荐   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>
源代码网推荐   这个文件是用来显示新闻的内容,其中各个意思大家一看就明白,我就不在这儿多说了。
源代码网推荐  
源代码网推荐  下面给大家看新闻列表显示的页面。
源代码网推荐   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" %>
源代码网推荐   <html>
源代码网推荐   <head>
源代码网推荐   <title>
源代码网推荐   </title>
源代码网推荐   <script language="c#" runat="server">
源代码网推荐   public string xslt()
源代码网推荐   {
源代码网推荐   StringWriter writer = new StringWriter();
源代码网推荐   //装入xml对象
源代码网推荐   XmlDocument xmldoc= new XmlDocument();
源代码网推荐   xmldoc.Load(Server.MapPath("Contents.xml"));
源代码网推荐   //装入xsl对象
源代码网推荐   XslTransform xsldoc = new XslTransform();
源代码网推荐   xsldoc.Load(Server.MapPath("news.xsl"));
源代码网推荐   //把xml转化成html页面
源代码网推荐   DocumentNavigator nav= new DocumentNavigator(xmldoc);
源代码网推荐   xsldoc.Transform(nav,null,writer);
源代码网推荐   return writer.ToString();
源代码网推荐  
源代码网推荐   }
源代码网推荐   </script>
源代码网推荐   </head>
源代码网推荐   <body>
源代码网推荐   <%=xslt()%>
源代码网推荐   <p align="center">该程序由<a href="http://www.aspcool.com">www.aspcool.com</a>设计制作.</p>
源代码网推荐  
源代码网推荐   </body>
源代码网推荐   </html>
源代码网推荐   这个页面完成了从xml通过xslt转化成html文件,也使我对于xslt有了进一步的认识。
源代码网推荐  
源代码网推荐   下面是新闻内容显示的页面:
源代码网推荐   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" %>
源代码网推荐   <html>
源代码网推荐   <head>
源代码网推荐   <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>
源代码网推荐   </head>
源代码网推荐   <body>
源代码网推荐   <%=xslt()%>
源代码网推荐   <p align="center">该程序由<a href="http://www.5ud.com">www.5ud.com</a>设计制作.</p>
源代码网推荐  
源代码网推荐   </body>
源代码网推荐   </html>
源代码网推荐  
源代码网推荐  
源代码网推荐   这个功能和上面的一样,我在这儿就不多说了。
源代码网推荐  
源代码网推荐  最后,大家来看一下最负责的一个页面,这个页面的作用就是用来建立新的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 (" ","</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: 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; 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">
源代码网推荐   摘要:
源代码网推荐   </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">
源代码网推荐   内容:
源代码网推荐   </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=重置 name=Button2 runat="server" OnServerClick="Button2_Click" DESIGNTIMEDRAGDROP="59">
源代码网推荐   <br>
源代码网推荐   <br>
源代码网推荐   <div id=mess runat=server>
源代码网推荐   </div>
源代码网推荐   <br>
源代码网推荐   <input type="button" value="提交" OnServerClick="Button1_Click" runat="server" ID="Button1" NAME="Button1" style="Z-INDEX: 112; LEFT: 268px; POSITION: absolute; TOP: 430px">
源代码网推荐   </form>
源代码网推荐   </body>
源代码网推荐   </HTML>
源代码网推荐  
源代码网推荐   此程序在.net beta2 build 9148下测试通过。(完)
源代码网推荐  
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华