Updating a XUL overlay UI through javascript - Mozilla

This is a discussion on Updating a XUL overlay UI through javascript - Mozilla ; Hi, I have a listbox in my XUL Overlay. I want to be able to read the name-value pairs from an XML file. I am able to parse the XML file and create a listitem element. The problem is, when ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Updating a XUL overlay UI through javascript

  1. Updating a XUL overlay UI through javascript

    Hi,

    I have a listbox in my XUL Overlay. I want to be able to read the name-value
    pairs from an XML file. I am able to parse the XML file and create a
    listitem element. The problem is, when I try to append this element using
    the appendChild method on the listbox, the element does not get added,
    although it does not return with an error.

    The code snippet:

    createLabelBox: function()
    {
    var data = "";

    var fstream = Components.classes["@
    mozilla.org/network/file-input-stream;1"]

    ..createInstance(Components.interfaces.nsIFileInpu tStream);

    var sstream = Components.classes["@
    mozilla.org/scriptableinputstream;1"]

    ..createInstance(Components.interfaces.nsIScriptab leInputStream);

    var file = Components.classes["@mozilla.org/file/directory_service;1
    "]

    ..getService(Components.interfaces.nsIProperties)
    .get("Home", Components.interfaces.nsIFile);

    file.append("labels.xml");

    fstream.init(file, -1, 0, 0);
    sstream.init(fstream);

    var str = sstream.read(4096);
    while (str.length > 0) {
    data += str;
    str = sstream.read(4096);
    }

    sstream.close();
    fstream.close();

    var domParser = new DOMParser();
    var dom = domParser.parseFromString(data, "text/xml");
    var labels = dom.getElementsByTagName("labels");
    var label = labels[0].getElementsByTagName("label");
    var lb =
    document.getElementById("LabelList"); // Note: This
    returns the XUL Object correctly

    const XUL_NS = "
    http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";

    for (i = 0 ; i < label.length ; i++)
    {
    var item = document.createElementNS(XUL_NS, "listitem"); //
    create a new XUL listitem
    item.setAttribute("label", label[i].getAttribute("name"));
    item.setAttribute("value", label[i].getAttribute("color"));
    lb.appendChild(item);
    }
    }


    Am I missing anything?

    -- Reema

  2. Re: Updating a XUL overlay UI through javascript

    On Apr 25, 7:50 pm, Reema wrote:
    > Hi,
    >
    > I have a listbox in my XUL Overlay. I want to be able to read the name-value
    > pairs from an XML file. I am able to parse the XML file and create a
    > listitem element. The problem is, when I try to append this element using
    > the appendChild method on the listbox, the element does not get added,
    > although it does not return with an error.
    >
    > The code snippet:
    >
    > createLabelBox: function()
    > {
    > var data = "";
    >
    > var fstream = Components.classes["@
    > mozilla.org/network/file-input-stream;1"]
    >
    > .createInstance(Components.interfaces.nsIFileInput Stream);
    >
    > var sstream = Components.classes["@
    > mozilla.org/scriptableinputstream;1"]
    >
    > .createInstance(Components.interfaces.nsIScriptabl eInputStream);
    >
    > var file = Components.classes["@mozilla.org/file/directory_service;1
    > "]
    >
    > .getService(Components.interfaces.nsIProperties)
    > .get("Home", Components.interfaces.nsIFile);
    >
    > file.append("labels.xml");
    >
    > fstream.init(file, -1, 0, 0);
    > sstream.init(fstream);
    >
    > var str = sstream.read(4096);
    > while (str.length > 0) {
    > data += str;
    > str = sstream.read(4096);
    > }
    >
    > sstream.close();
    > fstream.close();
    >
    > var domParser = new DOMParser();
    > var dom = domParser.parseFromString(data, "text/xml");
    > var labels = dom.getElementsByTagName("labels");
    > var label = labels[0].getElementsByTagName("label");
    > var lb =
    > document.getElementById("LabelList"); // Note: This
    > returns the XUL Object correctly
    >
    > const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
    >
    > for (i = 0 ; i < label.length ; i++)
    > {
    > var item = document.createElementNS(XUL_NS, "listitem"); //
    > create a new XUL listitem
    > item.setAttribute("label", label[i].getAttribute("name"));
    > item.setAttribute("value", label[i].getAttribute("color"));
    > lb.appendChild(item);
    > }
    >
    > }
    >
    > Am I missing anything?
    >
    > -- Reema


    If this is for something running on Mozilla 1.9, you could use XML
    Templates instead: http://developer.mozilla.org/en/docs...:XML_Templates

    Otherwise, make sure javascript.options.showInConsole is set to true
    in about:config. Try hard coding the label and value strings of the
    item to make sure that's not the problem.

    Zach

  3. Re: Updating a XUL overlay UI through javascript

    Thanks Zack..Hardcoding did not work too..I did not know about XML
    Templates..I will try it out..

    Thanks,
    - Reema

    On Thu, May 1, 2008 at 10:59 PM, Zach wrote:

    > On Apr 25, 7:50 pm, Reema wrote:
    > > Hi,
    > >
    > > I have a listbox in my XUL Overlay. I want to be able to read the

    > name-value
    > > pairs from an XML file. I am able to parse the XML file and create a
    > > listitem element. The problem is, when I try to append this element

    > using
    > > the appendChild method on the listbox, the element does not get added,
    > > although it does not return with an error.
    > >
    > > The code snippet:
    > >
    > > createLabelBox: function()
    > > {
    > > var data = "";
    > >
    > > var fstream = Components.classes["@
    > > mozilla.org/network/file-input-stream;1"]
    > >
    > > .createInstance(Components.interfaces.nsIFileInput Stream);
    > >
    > > var sstream = Components.classes["@
    > > mozilla.org/scriptableinputstream;1"]
    > >
    > > .createInstance(Components.interfaces.nsIScriptabl eInputStream);
    > >
    > > var file = Components.classes["@

    > mozilla.org/file/directory_service;1
    > > "]
    > >
    > > .getService(Components.interfaces.nsIProperties)
    > > .get("Home",

    > Components.interfaces.nsIFile);
    > >
    > > file.append("labels.xml");
    > >
    > > fstream.init(file, -1, 0, 0);
    > > sstream.init(fstream);
    > >
    > > var str = sstream.read(4096);
    > > while (str.length > 0) {
    > > data += str;
    > > str = sstream.read(4096);
    > > }
    > >
    > > sstream.close();
    > > fstream.close();
    > >
    > > var domParser = new DOMParser();
    > > var dom = domParser.parseFromString(data, "text/xml");
    > > var labels = dom.getElementsByTagName("labels");
    > > var label = labels[0].getElementsByTagName("label");
    > > var lb =
    > > document.getElementById("LabelList"); // Note:

    > This
    > > returns the XUL Object correctly
    > >
    > > const XUL_NS = "

    > http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
    > >
    > > for (i = 0 ; i < label.length ; i++)
    > > {
    > > var item = document.createElementNS(XUL_NS, "listitem");

    > //
    > > create a new XUL listitem
    > > item.setAttribute("label", label[i].getAttribute("name"));
    > > item.setAttribute("value", label[i].getAttribute("color"));
    > > lb.appendChild(item);
    > > }
    > >
    > > }
    > >
    > > Am I missing anything?
    > >
    > > -- Reema

    >
    > If this is for something running on Mozilla 1.9, you could use XML
    > Templates instead:
    > http://developer.mozilla.org/en/docs...:XML_Templates
    >
    > Otherwise, make sure javascript.options.showInConsole is set to true
    > in about:config. Try hard coding the label and value strings of the
    > item to make sure that's not the problem.
    >
    > Zach
    > _______________________________________________
    > dev-extensions mailing list
    > dev-extensions@lists.mozilla.org
    > https://lists.mozilla.org/listinfo/dev-extensions
    >


  4. Re: Updating a XUL overlay UI through javascript

    I tried this out. I followed the steps exactly as mentioned in the tutorial
    but It does not seem to work for me. Even a simple sample xul page taken
    from the examples on the dev.moz website does not work for me. The xml file
    resides at the same location where this xul file does. Opening this xul file
    in the browser does not show up anything. I am using FF 2.0.0.14 on Mac OSX.
    Let me know if I am doing anything wrong.














    On Fri, May 2, 2008 at 12:19 AM, Reema wrote:

    > Thanks Zack..Hardcoding did not work too..I did not know about XML
    > Templates..I will try it out..
    >
    > Thanks,
    > - Reema
    >
    >
    > On Thu, May 1, 2008 at 10:59 PM, Zach wrote:
    >
    > > On Apr 25, 7:50 pm, Reema wrote:
    > > > Hi,
    > > >
    > > > I have a listbox in my XUL Overlay. I want to be able to read the

    > > name-value
    > > > pairs from an XML file. I am able to parse the XML file and create a
    > > > listitem element. The problem is, when I try to append this element

    > > using
    > > > the appendChild method on the listbox, the element does not get added,
    > > > although it does not return with an error.
    > > >
    > > > The code snippet:
    > > >
    > > > createLabelBox: function()
    > > > {
    > > > var data = "";
    > > >
    > > > var fstream = Components.classes["@
    > > > mozilla.org/network/file-input-stream;1"]
    > > >
    > > > .createInstance(Components.interfaces.nsIFileInput Stream);
    > > >
    > > > var sstream = Components.classes["@
    > > > mozilla.org/scriptableinputstream;1"]
    > > >
    > > > .createInstance(Components.interfaces.nsIScriptabl eInputStream);
    > > >
    > > > var file = Components.classes["@

    > > mozilla.org/file/directory_service;1
    > > > "]
    > > >
    > > > .getService(Components.interfaces.nsIProperties)
    > > > .get("Home",

    > > Components.interfaces.nsIFile);
    > > >
    > > > file.append("labels.xml");
    > > >
    > > > fstream.init(file, -1, 0, 0);
    > > > sstream.init(fstream);
    > > >
    > > > var str = sstream.read(4096);
    > > > while (str.length > 0) {
    > > > data += str;
    > > > str = sstream.read(4096);
    > > > }
    > > >
    > > > sstream.close();
    > > > fstream.close();
    > > >
    > > > var domParser = new DOMParser();
    > > > var dom = domParser.parseFromString(data, "text/xml");
    > > > var labels = dom.getElementsByTagName("labels");
    > > > var label = labels[0].getElementsByTagName("label");
    > > > var lb =
    > > > document.getElementById("LabelList"); // Note:

    > > This
    > > > returns the XUL Object correctly
    > > >
    > > > const XUL_NS = "

    > > http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
    > > >
    > > > for (i = 0 ; i < label.length ; i++)
    > > > {
    > > > var item = document.createElementNS(XUL_NS, "listitem");

    > > //
    > > > create a new XUL listitem
    > > > item.setAttribute("label", label[i].getAttribute("name"));
    > > > item.setAttribute("value",

    > > label[i].getAttribute("color"));
    > > > lb.appendChild(item);
    > > > }
    > > >
    > > > }
    > > >
    > > > Am I missing anything?
    > > >
    > > > -- Reema

    > >
    > > If this is for something running on Mozilla 1.9, you could use XML
    > > Templates instead:
    > > http://developer.mozilla.org/en/docs...:XML_Templates
    > >
    > > Otherwise, make sure javascript.options.showInConsole is set to true
    > > in about:config. Try hard coding the label and value strings of the
    > > item to make sure that's not the problem.
    > >
    > > Zach
    > > _______________________________________________
    > > dev-extensions mailing list
    > > dev-extensions@lists.mozilla.org
    > > https://lists.mozilla.org/listinfo/dev-extensions
    > >

    >
    >


  5. Re: Updating a XUL overlay UI through javascript

    On Fri, May 2, 2008 at 3:05 PM, Reema wrote:
    > I tried this out. I followed the steps exactly as mentioned in the tutorial
    > but It does not seem to work for me. Even a simple sample xul page taken
    > from the examples on the dev.moz website does not work for me. The xml file
    > resides at the same location where this xul file does. Opening this xul file
    > in the browser does not show up anything. I am using FF 2.0.0.14 on Mac OSX.
    > Let me know if I am doing anything wrong.


    XML templates are Firefox 3 only feature, as the parent poster said.

    Nickolay

+ Reply to Thread