Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a local copy of an XML File for a Firefox Extension using Javascript
    text
    copied!<p>I am writing a Firefox extension. Right now I need to create a local copy of a XML file and I am almost successful. A File is read and a new one is created but this one is empty. Is there a special method for XML files or why does it not work?</p> <p>Here are the functions:</p> <pre><code>function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp = new XMLHttpRequest(); } else { xhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET", dname, false); xhttp.send(""); return xhttp.responseXML; } </code></pre> <p>and</p> <pre><code>function localcopy() { var url = content.document.location.href; var prefManagerr = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService) .getBranch("extensions.foafnet."); var prefStringx; if (prefManagerr.prefHasUserValue("stringpref1")) { prefStringx = prefManagerr.getCharPref("stringpref1"); } else { // Preference is default value so use that prefStringx = "0" } if (prefStringx == url) { xml = loadXMLDoc(prefStringx); var file = Components.classes["@mozilla.org/file/directory_service;1"]. getService(Components.interfaces.nsIProperties). get("TmpD", Components.interfaces.nsIFile); file.append("profiletemp.xml"); file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666); // do whatever you need to the created file alert(file.path); // var stream = Components.classes["@mozilla.org/network/safe-file-output-stream;1"]. createInstance(Components.interfaces.nsIFileOutputStream); stream.init(file, 0x04 | 0x08 | 0x20, 0600, 0); // readwrite, create, truncate stream.write(xml, xml.length); if (stream instanceof Components.interfaces.nsISafeOutputStream) { stream.finish(); } else { stream.close(); } } } </code></pre> <p>The beginning of the second function just declares, that a local copy is only to be made if the called website hast the same url as a url defined in the preferences of the extension. this part works just fine.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload