我想将一个XmlDocument对象的xml发送到HTTP客户端,但我担心建议的soltuion可能不会遵守Response已设置使用的编码:
public void ProcessRequest(HttpContext context)
{
XmlDocument doc = GetXmlToShow(context);
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetAllowResponseInBrowserHistory(true);
doc.Save(context.Response.OutputStream);
Run Code Online (Sandbox Code Playgroud)
}
如果我将编码更改为其他内容,例如Unicode,该怎么办?
public void ProcessRequest(HttpContext context)
{
XmlDocument doc = GetXmlToShow(context);
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.Unicode;
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.Cache.SetAllowResponseInBrowserHistory(true);
doc.Save(context.Response.OutputStream);
}
Run Code Online (Sandbox Code Playgroud)
请问Response.OutputStream翻译多数民众赞成被写入到它在运行中的二进制数据,并使其Unicode的?
或者Response.ContentEncoding只是提供信息?
如果ContentEncoding只是提供信息,那么以下文本字符串将返回什么内容编码?
context.Response.ContentEncoding = System.Text.Encoding.Unicode;
context.Response.Write("Hello World");
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Write("Hello World");
context.Response.ContentEncoding = System.Text.Encoding.UTF16;
context.Response.Write("Hello World");
context.Response.ContentEncoding = System.Text.Encoding.ASCII;
context.Response.Write("Hello World");
context.Response.ContentEncoding = System.Text.Encoding.BigEndianUnicode; …Run Code Online (Sandbox Code Playgroud) 这是一个非常基本的问题.我只是在学习ASP.NET(C#)的使命.我以前做过经典的ASP和PHP.
对于这个项目,我手上有ASP.NET 2.0.
我有一个Web表单,它有一个jqGrid Datagrid,我想通过AJAX提供XML数据.但是jqGrid不是问题所在."问题"是我应该采用的方法来生成XML.
我如何在ASP.NET中执行此操作?
做出决定后:如何输出XML?我不想使用ASP.NET的任何XML组件,因为它只是简单,简单的XML,彼此之后有一条记录.在这里使用System.Xml会有太大的开销.
<?xml version='1.0' encoding='utf-8'?>
<rows>
<page>1</page>
<total>25</total>
<records>3</records>
<row id='1'>
<cell>Row 1, Column 1</cell>
<cell>Row 1, Column 2</cell>
<cell>Row 1, Column 3</cell>
</row>
<row id='2'>
<cell>Row 2, Column 1</cell>
<cell>Row 2, Column 2</cell>
<cell>Row 2, Column 3</cell>
</row>
<row id='3'>
<cell>Row 3, Column 1</cell>
<cell>Row 3, Column 2</cell>
<cell>Row 3, Column 3</cell>
</row>
</rows>
Run Code Online (Sandbox Code Playgroud)
根据我以前使用其他脚本语言的经验,我只想打印出一个XML标签流(Response.Write).如果我在ASP.NET中这样做,我会下地狱吗?