I want to write an extension that involves XML - Mozilla

This is a discussion on I want to write an extension that involves XML - Mozilla ; Dear All, I want to develop an extension that somehow it has to write a string to a xml file. How can I do that? because I have to save some kind of options that user chooses. Do I have ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: I want to write an extension that involves XML

  1. I want to write an extension that involves XML

    Dear All,
    I want to develop an extension that somehow it has to write a string to
    a xml file. How can I do that? because I have to save some kind of
    options that user chooses.

    Do I have to use XPCOM? if so, Could you please provide an example?
    I did search in google, someone says that I cannot use javascript to
    save a file at client-side.

  2. Re: I want to write an extension that involves XML

    On Tue, 24 Jun 2008 00:57:37 +0700, Noppanit Charassinvichai wrote:

    > Dear All,
    > I want to develop an extension that somehow it has to write a string to
    > a xml file. How can I do that? because I have to save some kind of
    > options that user chooses.


    I guess the string is in a valid XML structure. I used to use the
    XMLSerializer[1] in this way:

    function saveToFile(data, file)
    {
    if (!data || !file) return;

    var fos = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutpu tStream);
    fos.init(file, 0x02 | 0x08 | 0x20, 0600, 0);
    var parser = new DOMParser();
    var doc = parser.parseFromString(data, "text/xml");
    var serializer = new XMLSerializer();
    serializer.serializeToStream(doc, fos, "UTF-8");
    fos.close();
    }

    Also `Writing to a file'[2] and the developer.mozilla.org[3] can be useful.

    > Do I have to use XPCOM? if so, Could you please provide an example? I
    > did search in google, someone says that I cannot use javascript to save
    > a file at client-side.


    You don't have to create a component to save your XML. If by saying
    `client-side' you mean your extension then someone is wrong. You *can*
    write[2] to a file.



    P.S.: I just created my first (singleton[4]) component and I can tell you
    it is a relief.



    [1] XMLSerializer - http://developer.mozilla.org/en/docs/XMLSerializer
    [2] Writing to a file - http://developer.mozilla.org/en/docs...ting_to_a_file
    [3] mozilla developer center - http://developer.mozilla.org
    [4] Using an XPCOM singleton component - http://developer.mozilla.org/en/docs...eton_component

    --
    Be excellent to each other. Party on, dudes. [Bill and Ted, 1989]

  3. Re: I want to write an extension that involves XML

    On Tue, 24 Jun 2008 00:57:37 +0700, Noppanit Charassinvichai wrote:

    > Dear All,
    > I want to develop an extension that somehow it has to write a string to
    > a xml file. How can I do that? because I have to save some kind of
    > options that user chooses.


    I guess the string is in a valid XML structure. I used to use the
    XMLSerializer[1] in this way:

    function saveToFile(data, file)
    {
    if (!data || !file) return;

    var fos = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutpu tStream);
    fos.init(file, 0x02 | 0x08 | 0x20, 0600, 0);
    var parser = new DOMParser();
    var doc = parser.parseFromString(data, "text/xml");
    var serializer = new XMLSerializer();
    serializer.serializeToStream(doc, fos, "UTF-8");
    fos.close();
    }

    Also `Writing to a file'[2] and the `developer.mozilla.org'[3] site can be
    useful.

    > Do I have to use XPCOM? if so, Could you please provide an example? I
    > did search in google, someone says that I cannot use javascript to save
    > a file at client-side.


    You don't have to create a component to save your XML. If by saying
    `client-side' you mean your extension then someone is wrong. You *can*
    write[2] to a file.



    P.S.: I just created my first (singleton[4]) component and I can tell you
    it is a relief (sharing data)!



    [1] XMLSerializer - http://developer.mozilla.org/en/docs/XMLSerializer
    [2] Writing to a file - http://developer.mozilla.org/en/docs...ting_to_a_file
    [3] mozilla developer center - http://developer.mozilla.org
    [4] Using an XPCOM singleton component - http://developer.mozilla.org/en/docs...eton_component

    --
    Be excellent to each other. Party on, dudes. [Bill and Ted, 1989]

+ Reply to Thread