HttpContext.Current.Response.ContentType = "text/xml";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpPostedFile file = HttpContext.Current.Request.Files[0];
// If file.InputSteam contains an "&", exception is thrown
XDocument doc = XDocument.Load(XmlReader.Create(file.InputStream));
HttpContext.Current.Response.Write(doc);
时有没有办法生成XML文档之前更换&
与&
?只要文件包含&
,我当前的代码就会崩溃。删除“和”从输入流生成XML
感谢
'&'表示一个字符引用的开始,如果后面的内容不是一个有效的引用,那么XML解析器应该抛出一个异常。听起来像你的问题是人们提交的不是XML的东西。不要丢弃数据位,捕获异常并向上传器返回错误消息。 – Quentin 2012-08-08 08:45:44