如何从code后面一个ASPX文件I输出XML? [英] How can I output XML from code behind in an ASPX file?

查看:193
本文介绍了如何从code后面一个ASPX文件I输出XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要输出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 Pages 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆