如何从code后面一个ASPX文件I输出XML? [英] How can I output XML from code behind in an ASPX file?
问题描述
我需要输出XML / ASX一个ASPX页面上。 XML是从code产生的身后,将看起来像这样。
I need to output XML / ASX on an ASPX page. The XML is generated from the code behind and will look like this.
我使用的字符串生成器来创建XML / ASX。
I'm using string builder to create the XML / ASX.
(...)
sb.AppendLine("<asx version='3.0'>");
sb.AppendLine("<title> Spilliste </title>");
while (i < pdc.Count)
{
sb.AppendLine("<entry>");
sb.AppendLine("<title>" + pdc[i].PageName + "</title>");
sb.AppendLine("<abstract> Ikke tilgjengelig</abstract>");
sb.AppendLine("<ref>" + pdc[i].LinkURL + "</ref>");
sb.AppendLine("</entry>");
i++;
}
sb.AppendLine("</asx>");
return sb.ToString();
(...)
但我怎么能输出吗?
But how can I output this?
的Response.Write
不会从code后面的工作。而且我明显的使用&LT; ASP:标签&gt;
在ASPX文件,因为它需要被放置在标签。我基本上有一个空白的ASPX页面。
Response.Write
does not work from code behind. And I'm notable to use <asp:label>
in the ASPX file, because it needs to be placed within tags. I basically have a blank ASPX page.
怎么办?
推荐答案
不要使用页
这一点。基本上页
是渲染HTML。如果您想发送XML或图像或任何其他类型的数据对于这个问题,你应该使用一个ashx的文件,而一个类实现的 的IHttpHandler
。
Don't use a Page
for this. Basically Page
s are for rendering html. If you want to send xml or images or any other type of data for that matter you should use a .ashx file and and a class that implements IHttpHandler
.
You can see this example on how to implement the interface.
这篇关于如何从code后面一个ASPX文件I输出XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!