最近在一个叫【网逻】的好地方,看到了这篇文章不错,与大家分享!现转载如下:这里我就用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="www.aspcool.comhttp://www.aspcool.com">www.aspcool.com</a>设计制作.
</p>
</body>
</html>
这个页面完成了从xml通过xslt转化成html文件,也使我对于xslt有了进一步的认识。
【回贴】 [原创] 续:用ASP.NET和XML做的新闻系统 作者:小猪哥 查看:0 回复:0
[第 7 楼] 发表于4/13/2005 21:2:56下面是新闻内容显示的页面:
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="www.aspcool.comhttp://www.aspcool.com">www.aspcool.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">
【回贴】 [原创] 回复:用ASP.NET和XML做的新闻系统 作者:小猪哥 查看:0 回复:0
[第 6 楼] 发表于4/13/2005 21:5:23public 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 ("\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="";
}
//向目录文件中写数据
}
由于界面的限制未完,大家可以自己去看看http://www.weblogic.com.cn还有不少好东东呢^_^
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="www.aspcool.comhttp://www.aspcool.com">www.aspcool.com</a>设计制作.
</p>
</body>
</html>
这个页面完成了从xml通过xslt转化成html文件,也使我对于xslt有了进一步的认识。
【回贴】 [原创] 续:用ASP.NET和XML做的新闻系统 作者:小猪哥 查看:0 回复:0
[第 7 楼] 发表于4/13/2005 21:2:56下面是新闻内容显示的页面:
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="www.aspcool.comhttp://www.aspcool.com">www.aspcool.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">
【回贴】 [原创] 回复:用ASP.NET和XML做的新闻系统 作者:小猪哥 查看:0 回复:0
[第 6 楼] 发表于4/13/2005 21:5:23public 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 ("\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="";
}
//向目录文件中写数据
}
由于界面的限制未完,大家可以自己去看看http://www.weblogic.com.cn还有不少好东东呢^_^
解决方案 »
- 机票黑屏系统上复制下来的,有哪位仁兄做过这样的财务系统
- 无法从“string”转换为“System.Data.DataColumn[]
- gridview的模板列中的hyperlink传递参数,如何绑定两个参数
- datagrid 编辑模式时候 请问,点击某一文本框 怎么达到复制效果/在线等。。。
- 请问如何获取到动态CheckBoxList的值!!!!
- 在线等。关于DataGrid小问题
- 关于DataGrid分页后,删除其中项问题.(急)
- 我接收的邮件里面有\r\n我怎么把它给消除了,Help me !!!!!1
- 谁有基于案例推理决策支持系统的相关代码呀?
- 在框架中弹出确认对话框的疑问?
- 求救,谁给我解释下啊?给20分!
- 如何把一页面导出成一个文件(doc,excel,pdf的都可以)
xml的数据内容全部都是可以看到的。
.............
[/GML]
hehe