----- Original Message ----
> From: Reema
> To: dev-extensions@lists.mozilla.org
> Cc: Eugene Borodin
> Sent: Friday, April 25, 2008 7:50:27 PM
> Subject: 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.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);
> }
> }
>


Idon't see what's wrong with your code, but I wanted to point out thatyou can simplify the beginning portion by reading the XML file usingXHR instead of nsIFileInputStream. XHR can read local files using thefile:// scheme.


Eric





__________________________________________________ __________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ