Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:33:22+00:00 2026-05-23T12:33:22+00:00

I am writing a Firefox extension. Right now I need to create a local

  • 0

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?

Here are the functions:

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;
}

and

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();
        }
    }
}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:33:23+00:00Added an answer on May 23, 2026 at 12:33 pm

    The first parameter to nsIOutputStream.write() has to be a string – you are giving it an XML document instead. You can use XMLSerializer to convert XML into text and to write it to a stream directly:

    new XMLSerializer().serializeToStream(xml, stream, "utf-8");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Firefox extension and I need to find the ip address of
I'm writing a Firefox extension that's to be used in house. Basically, I need
I'm writing an extension for Firefox, and I need to log some data to
I'm writing a Firefox extension that needs to inject a css file into webpages.
I am writing a firefox extension where I need a bidirectional scale element (
I'm writing a Firefox extension and I need to to access items in Firefox's
I am writing firefox extension with following install.rdf <?xml version=1.0?> <!--Copyright 2011, Example -->
I am now writing firefox 4 bootstrapped extension. The following is my story: When
I'm writing a new tab extension for Firefox, and I'd like to have a
I'm writing a firefox extension and really need to listen on TabOpen events and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.