"标签到输出-6ren"> "标签到输出-在使用 XmlSerializer 提供 XML 文档的 ASP.NET MVC 3 (.NET 4.0) 站点上并通过 Serialize() 序列化(相对简单)对象,我注意到在过去几周的某个时候,-6ren">
gpt4 book ai didi

.net - XmlSerializer 添加空 "<script/>"标签到输出

转载 作者:行者123 更新时间:2023-12-04 05:14:24 25 4
gpt4 key购买 nike

在使用 XmlSerializer 提供 XML 文档的 ASP.NET MVC 3 (.NET 4.0) 站点上并通过 Serialize() 序列化(相对简单)对象,我注意到在过去几周的某个时候,它开始插入一个空的 <script/>元素作为根级对象的第一个子元素。

例如一个用于序列化为..的对象

<Information xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MeetingInfo>
<VenueName>PORT MACQUARIE (NSW)</VenueName>
...

现在序列化为..
<Information xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<script/>
<MeetingInfo>
<VenueName>PORT MACQUARIE (NSW)</VenueName>
...

序列化由自定义 ActionResult 执行因此:
public class XmlResult<T> : ActionResult
{
public T Obj { get; set; }

public XmlResult(T obj)
{
this.Obj = obj;
}

public override void ExecuteResult(ControllerContext context)
{
var xs = new XmlSerializer(this.Obj.GetType());
context.HttpContext.Response.ContentType = "text/xml";
xs.Serialize(context.HttpContext.Response.Output, this.Obj);
}
}

没有名为 script 的变量代码库中的任何地方,当然不是在任何被序列化的对象中。

我将我的代码回滚到一个月前的位置(当时肯定是 而不是 插入 <script/> 标签,瞧,该代码现在正在插入它们。

这可能是从哪里来的?上个月是否有任何 Windows 更新影响了可能导致它的 .NET 框架?为什么?

最佳答案

回答我自己的问题——就像黑客帝国中没有勺子一样,也没有 <script/>标记。

在 Firefox 中查看响应 - 否 <script/>标记。

在 IE 中查看响应 - 否 <script/>标记。

但是在我常用的浏览器 Chrome 中查看响应,然后是 <script/>标记。

在 Chrome 中查看源代码(而不仅仅是将 XML 作为内容查看)- 否 <script/>标记。

因此,Chrome 显示 XML 内容时有些奇怪。与序列化无关。

编辑:追踪了它。这是Ripple模拟器作为 Blackberry 10 WebWorks SDK 的一部分安装。禁用 Chrome 扩展程序后,神秘 <script/>标签消失。

关于.net - XmlSerializer 添加空 "&lt;script/>"标签到输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14471223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com