8

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?

Shog9
  • 156,901
  • 35
  • 231
  • 235
paul perrault
  • 81
  • 1
  • 3

2 Answers2

13

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.

Dwhitz
  • 1,250
  • 7
  • 26
  • 38
bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • Do you have a list of broswers? Is there a way to check this constraint other then a broswer check? – Jeff Beck Dec 28 '09 at 03:43
  • No. Any any browser can change at any time. The only safe thing to do us to run code that doesn't care. – bmargulies Dec 28 '09 at 12:57
  • Oh well... what about that \p IE (8) accepts it all (length=25858) but Firefox doesn't... but IE doesn't accept w3School's new loadXMLDoc xhttp=new ActiveXObject("Microsoft.XMLHTTP") it worked with { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } :( Never tought it could be a browser problem... Have you got something more specific (filename?) to look for in the Apache solution? thanks for the hints... – paul perrault Dec 28 '09 at 14:21
  • Oh well... what about that [br] IE (8) accepts it all (length=25858) [br] but Firefox doesn't... [p] but IE doesn't accept w3School's new loadXMLDoc xhttp=new ActiveXObject("Microsoft.XMLHTTP"),[br] it worked with { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } [br] :( [br] Never tought it could be a browser problem... [br] Have you got something more specific (filename?) to look for in the Apache solution? [p] thanks for the hints... – paul perrault Dec 28 '09 at 14:28
  • Great! Your solution works fine. Thanks. What about XMLDOM/XMLHTTP should we stick to XMLDOM? – paul perrault Dec 28 '09 at 14:59
  • Please look at the entire source of js-utils.js from CXF, it addresses all of this. – bmargulies Dec 28 '09 at 19:38
  • Sorry, the name is cxf-utils.js. – bmargulies Dec 28 '09 at 19:39
2

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

zerokillex
  • 21
  • 1