这里是我用来响应xml数据的c#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class xmlData : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";
String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"+
"<note>"+
"<to>Tove</to>"+
"<from>Jani</from>"+
"<heading>Reminder</heading>"+
"<body>Don't forget me this weekend!</body>"+
"</note>";
Response.Write(xml);
}
}
但是我收到了这个错误.. 为什么?
This page contains the following errors:
error on line 3 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
最佳答案
您需要调用Response.End
阻止页面的其余部分在您的 XML 之后呈现 - 或者最好不要首先将其作为“页面”。毕竟它真的不是一个页面——它只是一些 XML。听起来您真的想要一个“处理程序”(ASHX 文件和一个实现 IHttpHandler
的类),它不会自动为您添加任何内容。
关于c# - xml写入错误 : "error on line 3 at column 1: Extra content at the end of the document",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9173002/