IE10,11连字符解析CDATA错误 [英] IE10, 11 CDATA with hyphens parsed wrong

查看:107
本文介绍了IE10,11连字符解析CDATA错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到过这样的问题:当我尝试解析从服务器接收到的xml时,包含在CDATA块中的消息在IE10中被解析,11直到找到第一个连字符。

I experienced such problem: when trying to parse xml that I receive from server, messages contained in CDATA blocks are parsed in IE10, 11 till first hyphens found.

请参阅我收到的XML示例:

See example of XML that I received:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<response>
    <task>results</task>
    <finish_msg><![CDATA[
      <div class="jq_results_container_outer">
        <div class="jq-msg-alert-0">
        </div>
      </div><br />]]>
   </finish_msg>
</response>

当我在IE 10中调用这样的Javascript代码时,11 var data = response.getElementsByTagName('finish_msg')[0] .firstChild.data
我得到 data 等于 < div class =jq_results_container_outer>< div class =jq

And when I called such Javascript code in IE 10, 11 var data = response.getElementsByTagName('finish_msg')[0].firstChild.data I get data equals to <div class="jq_results_container_outer"><div class="jq

一切适用于FF,Chrome,Opera,IE 8 ,9.
谢谢

Everything works for FF, Chrome, Opera, IE 8, 9. Thanks

推荐答案

查看这个向IE11提交的错误:

Have a look at this bug submission to IE11:

https://connect.microsoft.com/IE/feedback/details/1398926/ie11-does-not-parse-cdata-containing-hyphens-correctly

看来这个bug在Edge和IE11(11.0.10240.16431)中是固定的,但对我来说我仍然会在IE11上遇到这个错误。

It appears the bug is fixed in Edge and IE11 (11.0.10240.16431), but for me I still get the bug on IE11.

总结:

The bug can be summarized:

new DOMParser().parseFromString('<tag><![CDATA[data-with-hyphen]]></tag>', 'text/xml').firstChild.firstChild.nodeValue;

结果将有一个截断值,位于第一个连字符处。

The result will have a truncated value located at the first occurrence of a hyphen.

编辑:作为解决方法,您可以使用以下格式检索内容:

As a workaround, you can retrieve the contents using this format:

response.getElementsByTagName('finish_msg')[0].textContent

这篇关于IE10,11连字符解析CDATA错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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