Is there a 4096 character limit for JavaScript XML text nodes?

半腔热情 提交于 2019-11-28 10:13:23

Yes. Some browsers limit to 4096, and split longer texts into multiple text node children of the parent element. If you look at the source to Apache CXF you will find some utility Java script to deal with this, if no place else.

// Firefox splits large text regions into multiple Text objects (4096 chars in
// each). Glue it back together.
function getNodeText(node) {
    var r = "";
    for (var x = 0;x < node.childNodes.length; x++) {
        r = r + node.childNodes[x].nodeValue;
    }
    return r;
}

Also see:

http://svn.apache.org/repos/asf/cxf/trunk/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js

for more goodies in this neighborhood.

by the way, you can use normalize method to join all contiguous TextNode into one instead of looping them to obtain the text.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!