Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How is it that I always get only the first 4096 chars of a valid XML text node? (using JavaScript...) is a text node limited?

like image 236
paul perrault Avatar asked Dec 28 '09 02:12

paul perrault


2 Answers

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:

https://github.com/apache/cxf/blob/cxf-2.1.9/rt/javascript/src/main/resources/org/apache/cxf/javascript/cxf-utils.js

for more goodies in this neighborhood.

like image 88
bmargulies Avatar answered Oct 23 '22 14:10

bmargulies


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

like image 40
zerokillex Avatar answered Oct 23 '22 15:10

zerokillex