[Project_owners] Parsing local XML file

Didier Ernotte didier at ernotte.com
Thu Feb 10 14:25:37 EST 2005


If you use this:

    var file =
file=Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfD",
Components.interfaces.nsIFile);
    file.append("bioCyc.xml");

you have a object that refers to the bioCyc.xml file in your profile
directory on every platform.

Didier

--- Jawahar Swaminathan <jawahar at ebi.ac.uk> wrote:

> Dear Mozdev colleagues,
> 
> I'm trying to read a local XML file saved in the user profile
> directory 
> using the following code
> 
>     var xmlDoc =
> document.implementation.createDocument("","doc",null);
>     xmlDoc.async=false;
>     xmlDoc.load(fullname);
>     bbdatabase = xmlDoc.getElementsByTagName("database");
>     for(var i=0; i<bbdatabase.length; i++)
>       {
>       bbname =
>
bbdatabase[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
>       bbid =
> bbdatabase[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
>       bbdescription =
>
bbdatabase[i].getElementsByTagName("description")[0].childNodes[0].nodeValue
>       var menuItem = d.createElement("menuitem");
>       menuItem.setAttribute('label', bbname);
>       menuItem.setAttribute('value', bbid);
>       menuItem.setAttribute('tooltiptext', bbdescription);
>       p.appendChild(menuItem);
>      }
>     database.appendChild(p);
> 
> 
> The fullname in this case is a combination of the path to profile 
> directory and the xml file I want to read. alert statements tell me
> that 
> fullname is
> 
> /home/jawahar/.mozilla/firefox/gyocgivs.default/bioCyc.xml (a file
> which 
> actually exists) and has the structure
> 
> <?xml version="1.0"?>
> <database-collection>
>  <database>
>     <name>EcoCyc</name>
>     <id>ECOLI</id>
>     <description>E. coli</description>
>  </database>
> <etc....>
> 
> However, bbdatabase.length above is 0 and therefore nothing really is
> 
> done in the for loop.
> 
> If I change one line in the above code to
> 
> xmlDoc.load("file://" + fullname), the whole thing works. The full
> path 
> in quotes does not work either.
> 
> This obviously will work only on linux machines since the path to 
> profile directory will be with \\ in windows machines.
> 
> Am I doing something wrong ? And is there another more decent way of 
> reading a local XML file than the above ?
> 
> Any clues will be much appreciated.
> 
> regards - Jawahar
> 
> http://biobar.mozdev.org
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
> 



More information about the Project_owners mailing list