Off the top of my head, I don't see any reason why you couldn't structure an ASP.NET custom web control (ASCX file) to output only XML.
在我的脑海中,我没有看到任何原因导致您无法构建ASP.NET自定义Web控件(ASCX文件)以仅输出XML。
If you avoid using controls in the System.Web.UI namespace, and just use XML tags and sub-controls, which also render only XML, you should end up with a perfectly valid XML document being rendered.
如果您避免在System.Web.UI命名空间中使用控件,并且只使用XML标记和子控件(它们也只渲染XML),那么您应该最终得到一个完全有效的XML文档。
Am I right, or is there something I'm missing?
我是对的,还是有什么我想念的?
3 个解决方案
#1
If you want to generate an XML document and return that to the client, then it's probably easier if you create a http handler (IHttpHandler) instead of using a page and user controls.
如果要生成XML文档并将其返回给客户端,那么如果您创建一个http处理程序(IHttpHandler)而不是使用页面和用户控件,则可能更容易。
#2
You are missing that the control has to be within a page which would have some HTML output for a tag marking the start and finish of the control though there may be a way to override that.
您错过了控件必须位于页面内,该页面将为标记控件的开始和结束的标记提供一些HTML输出,尽管可能有一种方法可以覆盖它。
#3
Your idea could work out if your ASCX's generate pure XML, and you overwrite the Page's Render methods to replace the HTML tags that form HTML, BODY and FORM etc. elements.
如果您的ASCX生成纯XML,您的想法可以解决,并且您覆盖Page的Render方法来替换形成HTML,BODY和FORM等元素的HTML标记。
The question is what you would gain with this approach over simply generating an XML document and building a class library which generates those XML fragments you wanted to generate using the ASCX's.
问题是,通过这种方法可以获得什么,而不是简单地生成XML文档和构建一个类库,该类库生成您想要使用ASCX生成的XML片段。
#1
If you want to generate an XML document and return that to the client, then it's probably easier if you create a http handler (IHttpHandler) instead of using a page and user controls.
如果要生成XML文档并将其返回给客户端,那么如果您创建一个http处理程序(IHttpHandler)而不是使用页面和用户控件,则可能更容易。
#2
You are missing that the control has to be within a page which would have some HTML output for a tag marking the start and finish of the control though there may be a way to override that.
您错过了控件必须位于页面内,该页面将为标记控件的开始和结束的标记提供一些HTML输出,尽管可能有一种方法可以覆盖它。
#3
Your idea could work out if your ASCX's generate pure XML, and you overwrite the Page's Render methods to replace the HTML tags that form HTML, BODY and FORM etc. elements.
如果您的ASCX生成纯XML,您的想法可以解决,并且您覆盖Page的Render方法来替换形成HTML,BODY和FORM等元素的HTML标记。
The question is what you would gain with this approach over simply generating an XML document and building a class library which generates those XML fragments you wanted to generate using the ASCX's.
问题是,通过这种方法可以获得什么,而不是简单地生成XML文档和构建一个类库,该类库生成您想要使用ASCX生成的XML片段。