paul perrault
paul perrault

Reputation: 71

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?

Upvotes: 7

Views: 3766

Answers (2)

bmargulies
bmargulies

Reputation: 100133

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.

Upvotes: 12

zerokillex
zerokillex

Reputation: 21

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

Upvotes: 2

Related Questions