IE10, 11 CDATA with hyphens parsed wrong

2019-02-14 12:19发布

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.

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>

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

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

1条回答
乱世女痞
2楼-- · 2019-02-14 13:01

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

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.

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

response.getElementsByTagName('finish_msg')[0].textContent
查看更多
登录 后发表回答