C#读取XML显示到页面的问题

hblhshb 2005-11-18 09:23:39
在网上找了个XML存数据的新闻系统,是bate2版的.改了一下,可以运行了.但是显示不出东西来.不知道怎么回事儿.请各位帮忙.
显示新闻的程序news.aspx主要代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
this.Label1.Text = xslt();// 在此处放置用户代码以初始化页面
}
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);
System.Xml.XPath.XPathNavigator nav= xmldoc.CreateNavigator();
xsldoc.Transform(nav,null,writer,null);
return writer.ToString();
}
XML文件的内容:
<?xml version="1.0" encoding="GB2312"?>
<topiclist xmlns="http://tempuri.org/contents.xsd" 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>
<topic xmlns="">
<title>测试</title>
<href>main.aspx?name=2005</href>
</topic>
<topic xmlns="">
<title>fasdf</title>
<href>main.aspx?name=asdfas</href>
</topic>
</topiclist>

XSL文件news.xsl的内容:
<?xml version="1.0" encoding="GB2312" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="2" bgcolor="yellow">
<tr>
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="topiclist/topic">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="href"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
...全文
448 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hblhshb 2005-12-08
  • 打赏
  • 举报
回复
原来是<topiclist xmlns="http://tempuri.org/contents.xsd" type="AspCool News">
名称空间的问题.
blackhero 2005-12-04
  • 打赏
  • 举报
回复
http://blog.csdn.net/blackhero/archive/2005/09/02/470240.aspx
cqhydz 2005-12-04
  • 打赏
  • 举报
回复
多是字符集的问题
hblhshb 2005-11-18
  • 打赏
  • 举报
回复
有人知道是怎么回事儿吗?帮一下忙.分不够再加.谢谢了

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧