Инструменты пользователя

Инструменты сайта


software:firefox-xpi-programming:0ther

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Следующая версияСледующая версия справа и слева
software:firefox-xpi-programming:0ther [2010/01/29 11:12] – создано artursoftware:firefox-xpi-programming:0ther [2010/01/29 11:37] artur
Строка 24: Строка 24:
 }catch(e){alert(e)} }catch(e){alert(e)}
 </code> </code>
 +
 +===== Запись в файл =====
 +
 +<code js>function doXmlStuff () {
 +   var somefile = chromeToPath("chrome://path/to/file");
 +   var xmlDoc;
 +   var file = Components.classes["@mozilla.org/file/local;1"]
 +         .createInstance(Components.interfaces.nsILocalFile);
 +   file.initWithPath(somefile);
 +   if (!(file.exists())) {
 +      var fcStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
 +         .createInstance(Components.interfaces.nsIFileOutputStream);
 +      fcStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0); // write, create, truncate
 +
 +      var data = '<xml><rootnode></rootnode>';
 +      fcStream.write(data,data.length);
 +      fcStream.close
 +   }
 +
 +   xmlDoc = document.implementation.createDocument("","",null);
 +   xmlDoc.load("chrome://piratequesting/content/trainingLog.xml");
 +   xmlDoc.onload = function () {
 +      xmlDoc.documentElement.appendChild(....whatever you want to append....);
 +      var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
 +                         .createInstance(Components.interfaces.nsIFileOutputStream);
 +      //clear the file for writing the new doc
 +      foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0); // write, create, truncate
 +      var ser = new XMLSerializer();
 +      //write the serialized XML to file
 +      ser.serializeToStream(xmlDoc, foStream, "");
 +      foStream.close();   
 +   }
 +}</code>
software/firefox-xpi-programming/0ther.txt · Последнее изменение: 2017/03/23 21:59 — 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki