views:

347

answers:

1

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?

+6  A: 

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.

bmargulies
Do you have a list of broswers? Is there a way to check this constraint other then a broswer check?
Jeff Beck
No. Any any browser can change at any time. The only safe thing to do us to run code that doesn't care.
bmargulies
Oh well... what about that \pIE (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
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
Great! Your solution works fine. Thanks. What about XMLDOM/XMLHTTP should we stick to XMLDOM?
paul perrault
Please look at the entire source of js-utils.js from CXF, it addresses all of this.
bmargulies
Sorry, the name is cxf-utils.js.
bmargulies