1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function parse_file(filepath)
{
var aFile = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
aFile.initWithPath(filepath);
//alert(aFile.fileSize);
if (aFile.exists()) {
var aStream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
aStream.init(aFile, 0x01, 0444, null);
var domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"]
.getService(Components.interfaces.nsIDOMParser);
var root = domParser.parseFromStream(aStream,null,aFile.fileSize,"text/xml");
aStream.close();
return root;
}
} |