1

Utilising firefox (17.01), I am generating a xml code from uploaded .csv files. This code is going to be transformed to xhtml afterwards, but before, I need to create the valid xml file.

My entire code is

var parser = new DOMParser();
var xml_doc = parser.parseFromString(xml_code,'text/xml');
var xslhttp = new XMLHttpRequest();
xslhttp.open("GET",xsl_code,false);
xslhttp.send();
var xsl_doc = xslhttp.responseXML;

var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl_doc);
var xhtml_code = xsltProcessor.transformToFragment(xml_doc,document);

And it works as it should, except when I work with large files. In particular, the script is failing when xsl_code is as large as 112.039.355 (xml_code.length).

The error message is

NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMParser.parseFromString]

Is there any explanation for that? Any limitation with firefox? I know that if I eliminate content from the file, eventually the xml_doc will be correctly generated

Many thanks

GWorking
  • 4,011
  • 10
  • 49
  • 90

1 Answers1

0

Use a test for childNodes to see whether the document is over the 4096 character limit set by Firefox. If so, use a loop to concatenate the childNodes:

var nodes = xml_code.childNodes;
var xml_string = '';
var xml_doc;

if (nodes.length > 1)
  {
  for (var i = 0; i < nodes.length; i++)
    {  
    xml_string += nodes[i].nodeValue;
    }      
  }
else
  {
  xml_string = xml_code;
  }

with (new DOMParser() )
  {
  xml_doc = parseFromString(xml_string, "application/xml")
  }

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265