如何从ASP.NET输出XML? [英] How do you output XML from ASP.NET?

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

问题描述

我想知道如何制作ASP.NET输出XML而不是HTML。


这是我的情况:


我正在使用IE作为浏览公司文档的前端。让我们说,

a用户想要一个名为foobar的Word文档,然后他们会为getdoc.aspx?foobar
请求/>

现在getdoc.aspx做的是它从服务器获取Word文档

文件系统,对它进行XSLT转换以将其超链接到其他

文档,然后将超链接的WordML文档返回到

浏览器。


我想要的是IE显示转换后的Word文档在

浏览器的Word加载项。


我的问题是ASP.NET似乎想要返回HTML,而不是XML /

WordML。


使用XmlWriter我能够将WordML标记流式传输到

浏览器,但我得到了DOCTYPE和HTML代码附加到最后,所以

Word加载项无法触及它。


我尝试从页面中删除DOCTYPE和HTML标记设计

源代码在Visual Studio中,但随后VS抱怨验证():元素

''html''发生次数过多


我知道我可以使用WordML2HTML将WordML转换为HTML。 xslt,

但这既慢又不像将WordML加载到

浏览器加载项中那么漂亮。 (我希望客户端处理WordML

标签。)

我知道我可以通过WebService返回XML,但我不是想用WSDL处理

。我想要的只是让IIS返回原始的XML / WordML,以便浏览器可以加载它。


我需要一些特殊设置或DOCTYPE吗?设置为Visual

Studio以获取ASP以返回XML或者是一个Web窗体是错误的工具

我正在尝试做什么?
< br $> b $ b谢谢

保罗

I am wondering how to make ASP.NET output XML instead of HTML.

Here is my situation:

I am using IE as a front-end to browse company documents. Let''s say,
a user wants a Word document called foobar, then they''d do a http
request for "getdoc.aspx?foobar"

Now what getdoc.aspx does is it gets the Word document from the server
file system, does an XSLT transform on it to hyperlink it to other
documents and then returns the hyperlinked WordML document to the
browser.

What I want is for the IE to display the transformed Word document in
the browser''s Word Add-In.

My problem is that ASP.NET seems to want to return HTML, not XML/
WordML.

Using an XmlWriter I am able to stream the WordML markup to the
browser, but I get a DOCTYPE and HTML code appended to the end, so the
Word Add-In won''t touch it.

I tried deleting the DOCTYPE and HTML markup from the page design
source in Visual Studio, but then VS complains "Validation (): Element
''html'' occurs too few times".

I know I can transform the WordML into HTML using WordML2HTML.xslt,
but this is both slow and not as pretty as loading a WordML into the
browser Add-In. (I want the client to deal with processing the WordML
tags.)

I know I could return XML via a WebService, but I don''t want to deal
with the WSDL. All I want is for IIS to return the raw XML/WordML so
that the browser can load it.

Is there some special settings or DOCTYPE I need to set in Visual
Studio to get ASP to return XML or is a Web Form the wrong tool for
what I''m trying to do?

thanks
paul

推荐答案




这很容易。你只需要设置正确的内容类型(text / xml)和

就可以输出XML。有关示例,请查看直接向浏览器窗口发送XML

内容部分。
http://aspnet.4guysfromrolla.com/articles /092403-1.aspx


" li ****** @ aol.com"写道:
Hi,

It''s pretty easy. You just need to set the right content type (text/xml) and
just pump out the XML. For a sample, look at the section "Emitting XML
Content to the Browser Window Directly" on
http://aspnet.4guysfromrolla.com/articles/092403-1.aspx

"li******@aol.com" wrote:

我想知道如何使ASP.NET输出XML而不是HTML。


这是我的情况:


我使用IE作为浏览公司文档的前端。让我们说,

a用户想要一个名为foobar的Word文档,然后他们会为getdoc.aspx?foobar
请求/>

现在getdoc.aspx做的是它从服务器获取Word文档

文件系统,对它进行XSLT转换以将其超链接到其他

文档,然后将超链接的WordML文档返回到

浏览器。


我想要的是IE显示转换后的Word文档在

浏览器的Word加载项。


我的问题是ASP.NET似乎想要返回HTML,而不是XML /

WordML。


使用XmlWriter我能够将WordML标记流式传输到

浏览器,但我得到了DOCTYPE和HTML代码附加到最后,所以

Word加载项无法触及它。


我尝试从页面中删除DOCTYPE和HTML标记设计

源代码在Visual Studio中,但随后VS抱怨 ;验证():元素

''html''发生次数太少'。


我知道我可以使用WordML2HTML.xslt将WordML转换为HTML ,

但这既慢又不像将WordML加载到

浏览器加载项中那么漂亮。 (我希望客户端处理WordML

标签。)

我知道我可以通过WebService返回XML,但我不是想用WSDL处理

。我想要的只是让IIS返回原始的XML / WordML,以便浏览器可以加载它。


我需要一些特殊设置或DOCTYPE吗?设置为Visual

Studio以获取ASP以返回XML或者是一个Web窗体是错误的工具

我正在尝试做什么?


谢谢

paul

I am wondering how to make ASP.NET output XML instead of HTML.

Here is my situation:

I am using IE as a front-end to browse company documents. Let''s say,
a user wants a Word document called foobar, then they''d do a http
request for "getdoc.aspx?foobar"

Now what getdoc.aspx does is it gets the Word document from the server
file system, does an XSLT transform on it to hyperlink it to other
documents and then returns the hyperlinked WordML document to the
browser.

What I want is for the IE to display the transformed Word document in
the browser''s Word Add-In.

My problem is that ASP.NET seems to want to return HTML, not XML/
WordML.

Using an XmlWriter I am able to stream the WordML markup to the
browser, but I get a DOCTYPE and HTML code appended to the end, so the
Word Add-In won''t touch it.

I tried deleting the DOCTYPE and HTML markup from the page design
source in Visual Studio, but then VS complains "Validation (): Element
''html'' occurs too few times".

I know I can transform the WordML into HTML using WordML2HTML.xslt,
but this is both slow and not as pretty as loading a WordML into the
browser Add-In. (I want the client to deal with processing the WordML
tags.)

I know I could return XML via a WebService, but I don''t want to deal
with the WSDL. All I want is for IIS to return the raw XML/WordML so
that the browser can load it.

Is there some special settings or DOCTYPE I need to set in Visual
Studio to get ASP to return XML or is a Web Form the wrong tool for
what I''m trying to do?

thanks
paul


5月17日凌晨3:49,linha ... @ aol.com写道:
On May 17, 3:49 am, linha...@aol.com wrote:

使用XmlWriter我能够将WordML标记流式传输到

浏览器,但是我得到一个DOCTYPE和HTML代码附加到最后,所以

Word加载项不会触及它。
Using an XmlWriter I am able to stream the WordML markup to the
browser, but I get a DOCTYPE and HTML code appended to the end, so the
Word Add-In won''t touch it.



尝试设置Response.ContentType


Response.Clear();

响应。 ContentType =" text / xml";

Response.Write(xml);

Try to set Response.ContentType

Response.Clear();
Response.ContentType = "text/xml";
Response.Write(xml);


只是一个建议......在你的Page_Load活动,请尝试在

顶部添加:


Response.ContentType =" text / xml; charset = utf-8";


5月16日,9:49 pm,linha ... @ aol.com写道:
Just a suggestion...in your Page_Load event, try adding this at the
top:

Response.ContentType = "text/xml; charset=utf-8";

On May 16, 9:49 pm, linha...@aol.com wrote:

我想知道如何使ASP.NET输出XML而不是HTML。


这是我的情况:


我是使用IE作为前端来浏览公司文档。让我们说,

a用户想要一个名为foobar的Word文档,然后他们会为getdoc.aspx?foobar
请求/>

现在getdoc.aspx做的是它从服务器获取Word文档

文件系统,对它进行XSLT转换以将其超链接到其他

文档,然后将超链接的WordML文档返回到

浏览器。


我想要的是IE显示转换后的Word文档在

浏览器的Word加载项。


我的问题是ASP.NET似乎想要返回HTML,而不是XML /

WordML。


使用XmlWriter我能够将WordML标记流式传输到

浏览器,但我得到了DOCTYPE和HTML代码附加到最后,所以

Word加载项无法触及它。


我尝试从页面中删除DOCTYPE和HTML标记设计

源代码在Visual Studio中,但随后VS抱怨 ;验证():元素

''html''发生次数太少'。


我知道我可以使用WordML2HTML.xslt将WordML转换为HTML ,

但这既慢又不像将WordML加载到

浏览器加载项中那么漂亮。 (我希望客户端处理WordML

标签。)

我知道我可以通过WebService返回XML,但我不是想用WSDL处理

。我想要的只是让IIS返回原始的XML / WordML,以便浏览器可以加载它。


我需要一些特殊设置或DOCTYPE吗?设置为Visual

Studio以获取ASP以返回XML或者是一个Web窗体是错误的工具

我正在尝试做什么?


谢谢

paul
I am wondering how to make ASP.NET output XML instead of HTML.

Here is my situation:

I am using IE as a front-end to browse company documents. Let''s say,
a user wants a Word document called foobar, then they''d do a http
request for "getdoc.aspx?foobar"

Now what getdoc.aspx does is it gets the Word document from the server
file system, does an XSLT transform on it to hyperlink it to other
documents and then returns the hyperlinked WordML document to the
browser.

What I want is for the IE to display the transformed Word document in
the browser''s Word Add-In.

My problem is that ASP.NET seems to want to return HTML, not XML/
WordML.

Using an XmlWriter I am able to stream the WordML markup to the
browser, but I get a DOCTYPE and HTML code appended to the end, so the
Word Add-In won''t touch it.

I tried deleting the DOCTYPE and HTML markup from the page design
source in Visual Studio, but then VS complains "Validation (): Element
''html'' occurs too few times".

I know I can transform the WordML into HTML using WordML2HTML.xslt,
but this is both slow and not as pretty as loading a WordML into the
browser Add-In. (I want the client to deal with processing the WordML
tags.)

I know I could return XML via a WebService, but I don''t want to deal
with the WSDL. All I want is for IIS to return the raw XML/WordML so
that the browser can load it.

Is there some special settings or DOCTYPE I need to set in Visual
Studio to get ASP to return XML or is a Web Form the wrong tool for
what I''m trying to do?

thanks
paul



这篇关于如何从ASP.NET输出XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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