.net mysql , and the unreliable connection state. Micro Loans

Mozilla, javascript and xml parsing.

13 Nov 2006

So I did an ajax application, which used ajax to pass around potentially large amounts of xml (something i may choose not to repeat). Some very strange errors were appearing, which i traced to some nodes being truncated.

After much testing, i saw that the xml was intact, the node was intact, but when I used my GetNode function, it was truncated. Turns out that for very long (larger than 4096 characters) , the engine creates multiple text nodes, so the trusty node.firstChild.nodeValue only returned the first 4096 characters of the text!

The fix appears to be to iterate through the childnodes, building a string as you go, as done here.

getNodeValueDebug = function(node,key,debug){

if (!node || node.getElementsByTagName(key).length == 0||  node.getElementsByTagName(key) == null){ return null; } if (node.getElementsByTagName(key)[0].firstChild){

var val=""; var obtext = node.getElementsByTagName(key)[0];

//have to build it up to avoid truncation for(var cnt=0; cnt < obtext.childNodes.length; cnt++) {

if (debug){ alert(val.length +":"+obtext.childNodes[cnt].nodeValue.length); } val += obtext.childNodes[cnt].nodeValue; }

return val;

}else{ return null; } }