Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在我的页面上显示Rss_C#_Asp.net_Xml_Xslt_Rss - Fatal编程技术网

C# 如何在我的页面上显示Rss

C# 如何在我的页面上显示Rss,c#,asp.net,xml,xslt,rss,C#,Asp.net,Xml,Xslt,Rss,我已经使用下面的代码(aspx.cs)创建了xml文件,现在我正在尝试使用xslt和文本控件在页面上显示xml文件(查看我的aspx) aspx: <asp:Literal ID="RssHtml" runat="server" /> } xslt: 我做错了什么?我认为错误在于对Response.End()调用的误解,该调用“将所有当前缓冲的输出发送到客户端,停止页面的执行,并引发EndRequest事件。” 您应该

我已经使用下面的代码(aspx.cs)创建了xml文件,现在我正在尝试使用xslt和文本控件在页面上显示xml文件(查看我的aspx)

  • aspx:

                    <asp:Literal ID="RssHtml" runat="server" />
    

    }

  • xslt:




我做错了什么?

我认为错误在于对Response.End()调用的误解,该调用“将所有当前缓冲的输出发送到客户端,停止页面的执行,并引发EndRequest事件。”


您应该从代码片段中删除该行

您在web浏览器或rss客户端中收到了什么?提供的代码是否在一个web请求中运行?我没有收到任何内容…请描述用户故事(从用户角度看工作流)用户应如何请求rss页面以及该页面的外观,应该是页面上的任何其他内容,除非rss xml当我删除该行时,它会显示连接到母版页的所有页面。我无法理解您的答案,现在我迷失在您的原始问题中。但是,由于这些额外的不需要的内容,您在结果中收到了所需的xml吗?我收到了包含或不包含响应的xml。End().我需要删除以下行:Response.Clear();Response.ContentType=“应用程序/rss+xml”;Response.End();谢谢大家
Response.Clear();
Response.ContentType = "application/rss+xml";
XmlTextWriter objX = new XmlTextWriter(Server.MapPath("App_Code/RssDef.xml"), Encoding.UTF8);
objX.WriteStartDocument();
objX.WriteStartElement("rss");
objX.WriteAttributeString("version", "2.0");
objX.WriteStartElement("channel");

SqlCommand cmd = new SqlCommand("Select * from RssFeeds", new SqlConnection(ConfigurationManager.ConnectionStrings["igroup13_test1ConnectionString"].ConnectionString));
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();

objX.WriteElementString("title", "RSS.....");
objX.WriteElementString("link", "");
objX.WriteElementString("description", "desc");
objX.WriteElementString("language", "en-us");
objX.WriteElementString("ttl", "60");
objX.WriteElementString("lastBuildDate", String.Format("{0:R}", DateTime.Now));

while (dr.Read())
{
    objX.WriteStartElement("item");
    objX.WriteElementString("title", dr["title"].ToString());
    objX.WriteElementString("link", "");
    objX.WriteElementString("description", dr["description"].ToString());
    objX.WriteElementString("pubDate", String.Format("{0:R}", dr["publishDate"]));
    objX.WriteEndElement();
    //objX.WriteEndElement();
}

objX.WriteEndElement();
objX.WriteEndElement();
objX.WriteEndDocument();
objX.Flush();
objX.Close();
Response.End();


#region load the XML file
// Use my local XML file (that I've created)
String strXmlSrc = Server.MapPath("~/App_Code/RssDef.xml");

//  Load the XML file into the XmlDocument object.
XmlDocument myXmlDoc = new XmlDocument();
try
{
    myXmlDoc.Load(strXmlSrc);
}
catch (Exception ex)
{
    Response.Write("error in loading XML document " + ex.Message);
    return;
}
#endregion

#region load the XSLT file
//  Load our XSL file into the Xsl Transform object.
String strXslFile = Server.MapPath("~/App_Data/Def.xslt");
XslCompiledTransform myXslDoc = new XslCompiledTransform(true);
try
{
    myXslDoc.Load(strXslFile);
}
catch (Exception ex)
{
    Response.Write("error in loading XSLT document " + ex.Message);
    return;
}
#endregion

#region Transform the XML into XHTML
//  Create a StringBuilder and then point a StringWriter at it.
//  I'm using this to hold the HTML output by the Transform method
StringBuilder myStringBuilder = new StringBuilder();
StringWriter myStringWriter = new StringWriter(myStringBuilder);

try
{
    myXslDoc.Transform(myXmlDoc, null, myStringWriter);
}
catch (Exception ex)
{
    Response.Write("error in transforming the document " + ex.Message);
    return;
}
#endregion

#region Write to the HTML Page
//  Take theresulting HTML and display it via an ASP.NET
//  literal control.
RssHtml.Text = myStringBuilder.ToString();
#endregion


}
<xsl:for-each select="rss/channel">
  <h2>
    <a href="{link}">
      <xsl:value-of select="title" />        
    </a>

  </h2>
  <h4>
    <xsl:value-of select="description"/>
  </h4>
</xsl:for-each>

<ul>
  <xsl:for-each select="rss/channel/item">
    <li>
      <a href="{link}">
        <strong>
          <xsl:value-of select="title" />

        </strong>
      </a>

    </li>

    <xsl:value-of select="descreption"/>
    <br/>
    <xsl:value-of select="pubDate"/>

  </xsl:for-each>
</ul>