function Dummy_WriteCityNameToXML()
{
try
{
var CityName = document.getElementById("Dummy002").getAttribute("label");
const DIR_SERVICE = new Components.Constructor("@mozilla.org/file/directory_service;1","nsIProperties");
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
var path=(new DIR_SERVICE()).get("ProfD", Components.interfaces.nsIFile).path;
if (path.search(/\\/) != -1) { path = path + "\\"; } else { path = path + "/";}
path = path+"extensions\\"+XPI_ID+"\\xmls\\Dummysettings.xml";
file.initWithPath(path);
var is = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance( Components.interfaces.nsIFileInputStream );
is.init( file,0x01, 00004, null);
var sis = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance( Components.interfaces.nsIScriptableInputStream );
sis.init( is );
var detailoutput = sis.read( sis.available() );
is.close();
var OtherCompleteTagText = detailoutput;
var iStartIndex, iEndIndex;
iStartIndex=OtherCompleteTagText.indexOf("<lastSelectedCity");
OtherCompleteTagText=OtherCompleteTagText.substring(iStartIndex);
iEndIndex=OtherCompleteTagText.indexOf('/>');
OtherCompleteTagText=OtherCompleteTagText.substring(0, iEndIndex+2);
var OldStyleText = OtherCompleteTagText;
var NewStyleText = "<lastSelectedCity cityname='"+CityName+"'/>";
detailoutput = detailoutput.replace(OldStyleText, NewStyleText);
var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance( Components.interfaces.nsIFileOutputStream );
outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
var output = detailoutput;
var result = outputStream.write(detailoutput, detailoutput.length );
outputStream.close();
}
catch(ee)
{
alert(ee.message);
}
}
No comments:
Post a Comment