Firefox and javascript: 4kB limit for DOM text nodes

Ok, as I didn’t know about it, it’s probably my fault, but I’ve wasted some time on the problem and I want to put this here just for records.

I’m developing an application in javascript that reads some XML, as an AJAX response, and sort out the results. The problem is, when I try to access to a node via DOMParser, the node content is split into several children if this content is more than 4kB.

Let’s say my XML is in a form like the following:

<code>here a short code number</code>
<message>here a long long message</message>

So the javascript code looks like:

var xml = ajax.responseText;
var xmlDocument = (new DOMParser()).parseFromString(xml,'application/xml');
var code = xmlDocument.getElementsByTagName('code')[0].firstChild.nodeValue;
var message = xmlDocument.getElementsByTagName('message')[0].firstChild.nodeValue;

In this case the variable code is correctly set, as the <code> tag contains only a few bytes, instead the variable message doesn’t contain the whole <message> content, but only the first 4kB.

Simple workaround (maybe too simple?):

var message = ”;
var tmp = xmlDocument.getElementsByTagName(‘message’)[0];
for (i=0; ia known bug.


2 Responses to Firefox and javascript: 4kB limit for DOM text nodes

  1. John Liang says:

    Hi, this is exactly the same problem I am facing using FireFox. However in IE and Chrome no problem.

  2. Thankful Bum says:

    This problem made it onto Bugzilla years ago, but it hasn’t been fixed, yet. I’m new to Javascript and I spent the last 5hours with looking into every f****ng dirty corner of the web to get this problem solved. Your workaround works fine for me. Thank you very, very much! šŸ˜‰

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: