XMLDocument.save("localfile.xml") <possible solutions>

Lucky <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xml
Message-ID <[email protected]>
XMLDocument.prototype.save = function(localfile) {
   var C = Components.classes, I = Components.interfaces;

   var localFile = 
C["@mozilla.org/file/local;1"].createInstance(I.nsILocalFile);
   localFile.initWithPath(localfile);
   if (!localFile.exists()) localFile.create(localFile.NORMAL_FILE_TYPE, 
0644);

   var outputStream = 
C["@mozilla.org/network/file-output-stream;1"].createInstance(I.nsIFileOutputStream);
   outputStream.init(localFile, 0x04 | 0x08 | 0x20, 0644, 0);
   // 
<http://xulplanet.com/references/objref/XMLSerializer.html#method_serializeToStream>
   (new XMLSerializer).serializeToStream(this, outputStream, "UTF-8");
   outputStream.close();
}

XMLDocument.prototoype.save = function(localfile) {
   var C = Components.classes, I = Components.interfaces;

   var fos = C["@mozilla.org/file/local;1"].createInstance(I.nsILocalFile);
   fos.initWithPath(localfile);
   if (!fos.exists()) fos.create(fos.NORMAL_FILE_TYPE, 0644);

   var charset = "UTF-8"; // can be any character encoding name that 
Mozilla supports
   var os = 
C["@mozilla.org/intl/converter-output-stream;1"].createInstance(I.nsIConverterOutputStream);
   os.init(fos, charset, 0, 0x0000);
   //os.writeString("Umlaute: \u00FC \u00E4\n"); // direct JSString 
access, not needed here.
   //os.writeString("Hebrew:  \u05D0 \u05D1\n");

   (new XMLSerializer).serializeToStream(this, os, charset);
   os.close();
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.