Sending gmail mail to Drive as a pdf with attachment combined - google-apps-script

I currently have the following script that was working for us for a while. It was designed to take emails under a certain label, convert them to a pdf, and store them in a google drive folder. It works great. The problem now, is that it stores the email and attachments as separate files. We are trying to change it to where the attachment is combined with the message, so it is just one big pdf instead of multiple files.
The process was done manually for a while, but the load is getting too much. I have experimented with various codes but have had zero luck (I am not a great coder...).
function saveEmailasPDF() {
var gmailLabels = "Bill";
var driveFolder = "Emails";
var threads = GmailApp.search("in:" + gmailLabels, 0, 5);
if (threads.length > 0) {
// Google Drive folder
var folders = DriveApp.getFoldersByName(driveFolder);
var folder = folders.hasNext() ?
folders.next() : DriveApp.createFolder(driveFolder);
// Gmail Label
var label = GmailApp.getUserLabelByName(gmailLabels) ?
GmailApp.getUserLabelByName(gmailLabels) : GmailApp.createLabel(driveFolder);
for (var t=0; t<threads.length; t++) {
threads[t].removeLabel(label);
var msgs = threads[t].getMessages();
var html = "";
var attachments = [];
var subject = threads[t].getFirstMessageSubject();
// Combines the thread into an HTML document
for (var m=0; m<msgs.length; m++) {
var msg = msgs[m];
html += "From: " + msg.getFrom() + "<br />";
html += "To: " + msg.getTo() + "<br />";
html += "Date: " + msg.getDate() + "<br />";
html += "Subject: " + msg.getSubject() + "<br />";
html += "<hr />";
html += msg.getBody().replace(/<img[^>]*>/g,"");
html += "<hr />";
var atts = msg.getAttachments();
for (var a=0; a<atts.length; a++) {
attachments.push(atts[a]);
}
}
// Save the attachement to drive too and then add a link to the message pdf
if (attachments.length > 0) {
var footer = "<strong>Attachments:</strong><ul>";
for (var z=0; z<attachments.length; z++) {
var file = folder.createFile(attachments[z]);
footer += "<li><a href='" + file.getUrl() + "'>" + file.getName() + "</a></li>";
}
html += footer + "</ul>";
}
// Converts the email to a pdf. All the conversation will be in one pdf not seperated
var tempFile = DriveApp.createFile("temp.html", html, "text/html");
folder.createFile(tempFile.getAs("application/pdf")).setName(subject + ".pdf");
tempFile.setTrashed(true);
}
}
}

Related

Exception: Conversion from text/html to application/pdf failed - from yesterday

I was saving my emails as PDF. It was working well. It stopped working for the last few days with the error
Exception: Conversion from text/html to application/pdf failed
It is also reported by someone here :
It just stopped working - google-app-script google-drive-api createFile
function saveGmailAsPDF() {
var gmailLabels = "TESTING";
var driveFolder = "TEST2";
var threads = GmailApp.search("in:" + gmailLabels, 0, 5);
if (threads.length > 0) {
/* Google Drive folder where the Files would be saved */
var folders = DriveApp.getFoldersByName(driveFolder);
var folder = folders.hasNext() ?
folders.next() : DriveApp.createFolder(driveFolder);
/* Gmail Label that contains the queue */
var label = GmailApp.getUserLabelByName(gmailLabels) ?
GmailApp.getUserLabelByName(gmailLabels) : GmailApp.createLabel(driveFolder);
for (var t=0; t<threads.length; t++) {
//threads[t].removeLabel(label);
var msgs = threads[t].getMessages();
var html = "";
var attachments = [];
var subject = threads[t].getFirstMessageSubject();
/* Append all the threads in a message in an HTML document */
for (var m=0; m<msgs.length; m++) {
var msg = msgs[m];
html += "From: " + msg.getFrom() + "<br />";
html += "To: " + msg.getTo() + "<br />";
html += "Date: " + msg.getDate() + "<br />";
html += "Subject: " + msg.getSubject() + "<br />";
html += "<hr />";
html += msg.getBody().replace(/<img[^>]*>/g,"");
html += "<hr />";
var atts = msg.getAttachments();
for (var a=0; a<atts.length; a++) {
attachments.push(atts[a]);
}
}
/* Save the attachment files and create links in the document's footer */
if (attachments.length > 0) {
var footer = "<strong>Attachments:</strong><ul>";
for (var z=0; z<attachments.length; z++) {
var file = folder.createFile(attachments[z]);
footer += "<li><a href='" + file.getUrl() + "'>" + file.getName() + "</a></li>";
}
html += footer + "</ul>";
}
/* Convert the Email Thread into a PDF File */
//The PDF craeted is damaged by the below code
//var blob = Utilities.newBlob(html, "application/pdf").setName("mail" + ".pdf");
//var theFolderId = '{FOLDER ID}';
//var parentFolder = DriveApp.getFolderById(theFolderId);
//folder.createFile(blob);
// PDF is damaged by the below code
//var html = "<h1>Hello world</h1>";
//var blob = Utilities.newBlob(html, "application/pdf", "text.pdf");
//DriveApp.createFile(blob);
//the below code was working well.
var tempFile = DriveApp.createFile("temp.html", html, "text/html");
//the bellow line is giving the error for the last few days
//Error : Exception: Conversion from text/html to application/pdf failed
folder.createFile(tempFile.getAs("application/pdf")).setName(subject + ".pdf");
tempFile.setTrashed(true);
}
}
}
This seems to be an ongoing bug. It seems that it has already been reported to Google Issue Tracker. Go to the issue and click the white star (☆) at the top-left (just left of the issue ID) to increase its priority.

Google Apps Script: Saving Gmail Attachment to Google Drive and replacement of characters in the saved attachment file name

how can I swap characters from the filename that is saved in GDrive? e.g. "/" to "-"
I am using this great script -> https://github.com/ahochsteger/gmail2gdrive/blob/master/Code.gs &
https://github.com/ahochsteger/gmail2gdrive/blob/master/Config.gs
It works really well.
But i would like to exchange letters for the attachment filename that is saved.
I use this script from https://github.com/ahochsteger/gmail2gdrive:
Code.gs
// Gmail2GDrive
// https://github.com/ahochsteger/gmail2gdrive
/**
* Returns the label with the given name or creates it if not existing.
*/
function getOrCreateLabel(labelName) {
var label = GmailApp.getUserLabelByName(labelName);
if (label == null) {
label = GmailApp.createLabel(labelName);
}
return label;
}
/**
* Recursive function to create and return a complete folder path.
*/
function getOrCreateSubFolder(baseFolder,folderArray) {
if (folderArray.length == 0) {
return baseFolder;
}
var nextFolderName = folderArray.shift();
var nextFolder = null;
var folders = baseFolder.getFolders();
while (folders.hasNext()) {
var folder = folders.next();
if (folder.getName() == nextFolderName) {
nextFolder = folder;
break;
}
}
if (nextFolder == null) {
// Folder does not exist - create it.
nextFolder = baseFolder.createFolder(nextFolderName);
}
return getOrCreateSubFolder(nextFolder,folderArray);
}
/**
* Returns the GDrive folder with the given path.
*/
function getFolderByPath(path) {
var parts = path.split("/");
if (parts[0] == '') parts.shift(); // Did path start at root, '/'?
var folder = DriveApp.getRootFolder();
for (var i = 0; i < parts.length; i++) {
var result = folder.getFoldersByName(parts[i]);
if (result.hasNext()) {
folder = result.next();
} else {
throw new Error( "folder not found." );
}
}
return folder;
}
/**
* Returns the GDrive folder with the given name or creates it if not existing.
*/
function getOrCreateFolder(folderName) {
var folder;
try {
folder = getFolderByPath(folderName);
} catch(e) {
var folderArray = folderName.split("/");
folder = getOrCreateSubFolder(DriveApp.getRootFolder(), folderArray);
}
return folder;
}
/**
* Processes a message
*/
function processMessage(message, rule, config) {
Logger.log("INFO: Processing message: "+message.getSubject() + " (" + message.getId() + ")");
var messageDate = message.getDate();
var attachments = message.getAttachments();
for (var attIdx=0; attIdx<attachments.length; attIdx++) {
var attachment = attachments[attIdx];
Logger.log("INFO: Processing attachment: "+attachment.getName());
var match = true;
if (rule.filenameFromRegexp) {
var re = new RegExp(rule.filenameFromRegexp);
match = (attachment.getName()).match(re);
}
if (!match) {
Logger.log("INFO: Rejecting file '" + attachment.getName() + " not matching" + rule.filenameFromRegexp);
continue;
}
try {
var folder = getOrCreateFolder(Utilities.formatDate(messageDate, config.timezone, rule.folder));
var file = folder.createFile(attachment);
var filename = file.getName();
if (rule.filenameFrom && rule.filenameTo && rule.filenameFrom == file.getName()) {
filename = Utilities.formatDate(messageDate, config.timezone, rule.filenameTo.replace('%s',message.getSubject()));
Logger.log("INFO: Renaming matched file '" + file.getName() + "' -> '" + filename + "'");
file.setName(filename);
}
else if (rule.filenameTo) {
filename = Utilities.formatDate(messageDate, config.timezone, rule.filenameTo.replace('%s',message.getSubject()));
Logger.log("INFO: Renaming '" + file.getName() + "' -> '" + filename + "'");
file.setName(filename);
}
file.setDescription("Mail title: " + message.getSubject() + "\nMail date: " + message.getDate() + "\nMail link: https://mail.google.com/mail/u/0/#inbox/" + message.getId());
Utilities.sleep(config.sleepTime);
} catch (e) {
Logger.log(e);
}
}
}
/**
* Generate HTML code for one message of a thread.
*/
function processThreadToHtml(thread) {
Logger.log("INFO: Generating HTML code of thread '" + thread.getFirstMessageSubject() + "'");
var messages = thread.getMessages();
var html = "";
for (var msgIdx=0; msgIdx<messages.length; msgIdx++) {
var message = messages[msgIdx];
html += "From: " + message.getFrom() + "<br />\n";
html += "To: " + message.getTo() + "<br />\n";
html += "Date: " + message.getDate() + "<br />\n";
html += "Subject: " + message.getSubject() + "<br />\n";
html += "<hr />\n";
html += message.getBody() + "\n";
html += "<hr />\n";
}
return html;
}
/**
* Generate a PDF document for the whole thread using HTML from .
*/
function processThreadToPdf(thread, rule) {
Logger.log("INFO: Saving PDF copy of thread '" + thread.getFirstMessageSubject() + "'");
var folder = getOrCreateFolder(rule.folder);
var html = processThreadToHtml(thread);
var blob = Utilities.newBlob(html, 'text/html');
var pdf = folder.createFile(blob.getAs('application/pdf')).setName(thread.getFirstMessageSubject() + ".pdf");
return pdf;
}
/**
* Main function that processes Gmail attachments and stores them in Google Drive.
* Use this as trigger function for periodic execution.
*/
function Gmail2GDrive() {
if (!GmailApp) return; // Skip script execution if GMail is currently not available (yes this happens from time to time and triggers spam emails!)
var config = getGmail2GDriveConfig();
var label = getOrCreateLabel(config.processedLabel);
var end, start, runTime;
start = new Date(); // Start timer
Logger.log("INFO: Starting mail attachment processing.");
if (config.globalFilter===undefined) {
config.globalFilter = "has:attachment -in:trash -in:drafts -in:spam";
}
// Iterate over all rules:
for (var ruleIdx=0; ruleIdx<config.rules.length; ruleIdx++) {
var rule = config.rules[ruleIdx];
var gSearchExp = config.globalFilter + " " + rule.filter + " -label:" + config.processedLabel;
if (config.newerThan != "") {
gSearchExp += " newer_than:" + config.newerThan;
}
var doArchive = rule.archive == true;
var doPDF = rule.saveThreadPDF == true;
// Process all threads matching the search expression:
var threads = GmailApp.search(gSearchExp);
Logger.log("INFO: Processing rule: "+gSearchExp);
for (var threadIdx=0; threadIdx<threads.length; threadIdx++) {
var thread = threads[threadIdx];
end = new Date();
runTime = (end.getTime() - start.getTime())/1000;
Logger.log("INFO: Processing thread: "+thread.getFirstMessageSubject() + " (runtime: " + runTime + "s/" + config.maxRuntime + "s)");
if (runTime >= config.maxRuntime) {
Logger.log("WARNING: Self terminating script after " + runTime + "s");
return;
}
// Process all messages of a thread:
var messages = thread.getMessages();
for (var msgIdx=0; msgIdx<messages.length; msgIdx++) {
var message = messages[msgIdx];
processMessage(message, rule, config);
}
if (doPDF) { // Generate a PDF document of a thread:
processThreadToPdf(thread, rule);
}
// Mark a thread as processed:
thread.addLabel(label);
if (doArchive) { // Archive a thread if required
Logger.log("INFO: Archiving thread '" + thread.getFirstMessageSubject() + "' ...");
thread.moveToArchive();
}
}
}
end = new Date(); // Stop timer
runTime = (end.getTime() - start.getTime())/1000;
Logger.log("INFO: Finished mail attachment processing after " + runTime + "s");
}
and for Config.gs:
/**
* Configuration for Gmail2GDrive
* See https://github.com/ahochsteger/gmail2gdrive/blob/master/README.md for a config reference
*/
function getGmail2GDriveConfig() {
return {
// Global filter
"globalFilter": "-in:trash -in:drafts -in:spam",
// Gmail label for processed threads (will be created, if not existing):
"processedLabel": "to-gdrive/processed",
// Sleep time in milli seconds between processed messages:
"sleepTime": 100,
// Maximum script runtime in seconds (google scripts will be killed after 5 minutes):
"maxRuntime": 280,
// Only process message newer than (leave empty for no restriction; use d, m and y for day, month and year):
"newerThan": "1m",
// Timezone for date/time operations:
"timezone": "GMT",
// Processing rules:
"rules": [
{ // Store all attachments sent to my.name+scans#gmail.com to the folder "Scans"
"filter": "has:attachment to:my.name+scans#gmail.com",
"folder": "'Scans'-yyyy-MM-dd"
},
{ // Store all attachments from example1#example.com to the folder "Examples/example1"
"filter": "has:attachment from:example1#example.com",
"folder": "'Examples/example1'"
},
{ // Store all pdf attachments from example2#example.com to the folder "Examples/example2"
"filter": "has:attachment from:example2#example.com",
"folder": "'Examples/example2'",
"filenameFromRegexp": ".*\.pdf$"
},
{ // Store all attachments from example3a#example.com OR from:example3b#example.com
// to the folder "Examples/example3ab" while renaming all attachments to the pattern
// defined in 'filenameTo' and archive the thread.
"filter": "has:attachment (from:example3a#example.com OR from:example3b#example.com)",
"folder": "'Examples/example3ab'",
"filenameTo": "'file-'yyyy-MM-dd-'%s.txt'",
"archive": true
},
{
// Store threads marked with label "PDF" in the folder "PDF Emails" als PDF document.
"filter": "label:PDF",
"saveThreadPDF": true,
"folder": "PDF Emails"
},
{ // Store all attachments named "file.txt" from example4#example.com to the
// folder "Examples/example4" and rename the attachment to the pattern
// defined in 'filenameTo' and archive the thread.
"filter": "has:attachment from:example4#example.com",
"folder": "'Examples/example4'",
"filenameFrom": "file.txt",
"filenameTo": "'file-'yyyy-MM-dd-'%s.txt'"
}
]
};
}
I use this part to save the PDF attachments
{ // Store all pdf attachments from example2#example.com to the folder "Examples/example2"
"filter": "has:attachment from:example2#example.com",
"folder": "'Examples/example2'",
"filenameFromRegexp": ".*\.pdf$"
},
However, the character "/" is often used in the filename of the attachment. e.g. "Konto/postbox3226.pdf"
How can I replace this with e.g. "-" to "Konto-postbox3226.pdf"
Does that work with the replace command? If so, how do I have to use this?
many thanks for your help
Okay, I have taken a deeper look at the code and I found how to change the name of the file that it is stored in Google Drive.
In code.gs line 92:
try {
var folder = getOrCreateFolder(Utilities.formatDate(messageDate, config.timezone, rule.folder));
// NEW CODE
var new_filename = attachment.getName()
new_filename = new_filename.replace('/','-')
attachment.setName(new_filename)
var file = folder.createFile(attachment);
Reference
File.getName()
File.setName(name)
Folder.createFile(blob)
Let me know if that finally works

Google Drive and Translation Script

I am using this script, but each time it fetches the RSS it creates a new HTML file.
I would like it to just rewrite the previous file instead of creating a new one and fetch only once a day. After that once i share the file is not validated in RSS Validator if there is any way to fix this changing mime or any other option. Any help with this would be appreciated.
function doGet() {
var fromLang = "en";
var toLang = "es";
var rssFeed = "http://xkcd.com/rss.xml";
var feed = parseRSS(rssFeed, fromLang, toLang);
DriveApp.createFile("rssTest", feed, MimeType.HTML);
return ContentService.createTextOutput(feed)
.setMimeType(ContentService.MimeType.RSS);
}
function parseRSS(feed, fromLang, toLang) {
var id = Utilities.base64Encode(feed + fromLang + toLang);
// Cache the RSS feeds for an hour
var cache = CacheService.getPublicCache();
var rss = cache.get(id);
if (rss != null) {
return rss;
}
var item, date, title, link, desc, guid;
var txt = UrlFetchApp.fetch(feed).getContentText();
var doc = Xml.parse(txt, false);
title = doc.getElement().getElement("channel").getElement("title").getText();
// The RSS Feed is translated using Google Translate
rss = '<rss version="2.0">';
rss += "<channel><title>";
rss += LanguageApp.translate(title, fromLang, toLang);
rss += " (" + title + ")</title>";
var items = doc.getElement().getElement("channel").getElements("item");
// Parsing single items in the RSS Feed
for (var i in items) {
try {
item = items[i];
title = item.getElement("title").getText();
link = item.getElement("link").getText();
date = item.getElement("pubDate").getText();
desc = item.getElement("description").getText();
guid = Utilities.base64Encode(link + fromLang + toLang);
title = LanguageApp.translate(title, fromLang, toLang);
desc = LanguageApp.translate(desc, fromLang, toLang,
{contentType: "html"});
rss += "<item>";
rss += " <title>" + title + "</title>";
rss += " <link>" + link + "</link>";
rss += " <pubDate>" + date + "</pubDate>";
rss += " <guid>" + guid + "</guid>";
rss += " <description><![CDATA[" + desc + "]]></description>";
rss += "</item>";
} catch (e) {
Logger.log(e);
}
}
rss += "</channel></rss>";
cache.put(id, rss, 3600);
return rss;
}
You can change the content of a file by just calling the method setContent(). And if you know the ID you can get the file through DriveApp.getFileById().
So this part of your code:
DriveApp.createFile("rssTest", feed, MimeType.HTML);
Can change to this:
var file = DriveApp.getFileById("<your file ID>");
file.setContent(feed);
I've tried to validate this RSS in the validator you sent.
There are some things that I needed to do in order to validate.
In the guid tag there is an error, basically, you need to add isPermaLink="false".
After that remember that the channel elements needs description element and link check it at w3schools.
Doing that made it a valid RSS for me. So you need to change your parseRSS to make it work.
function parseRSS(feed, fromLang, toLang) {
var id = Utilities.base64Encode(feed + fromLang + toLang);
// Cache the RSS feeds for an hour
var cache = CacheService.getPublicCache();
var rss = cache.get(id);
if (rss != null) {
return rss;
}
var item, date, title, link, desc, guid;
var txt = UrlFetchApp.fetch(feed).getContentText();
var doc = Xml.parse(txt, false);
title = doc.getElement().getElement("channel").getElement("title").getText();
// The RSS Feed is translated using Google Translate
rss = '<rss version="2.0">';
rss += "<channel><title>";
rss += LanguageApp.translate(title, fromLang, toLang);
rss += " (" + title + ")</title>";
rss += "<description>Description you need to fill</description>"; // Add this line
rss += "<link>Link you need to fill</link>"; // Add this line
var items = doc.getElement().getElement("channel").getElements("item");
// Parsing single items in the RSS Feed
for (var i in items) {
try {
item = items[i];
title = item.getElement("title").getText();
link = item.getElement("link").getText();
date = item.getElement("pubDate").getText();
desc = item.getElement("description").getText();
guid = Utilities.base64Encode(link + fromLang + toLang);
title = LanguageApp.translate(title, fromLang, toLang);
desc = LanguageApp.translate(desc, fromLang, toLang,
{contentType: "html"});
rss += "<item>";
rss += " <title>" + title + "</title>";
rss += " <link>" + link + "</link>";
rss += " <pubDate>" + date + "</pubDate>";
rss += " <guid isPermaLink="false">" + guid + "</guid>"; // Modified this line
rss += " <description><![CDATA[" + desc + "]]></description>";
rss += "</item>";
} catch (e) {
Logger.log(e);
}
}
rss += "</channel></rss>";
cache.put(id, rss, 3600);
return rss;
}

Embed a video using Google Script

I'm trying to use Google Scripting to embed videos I have stored on my Google Drive into HTML. Here's the code I'm using to generate the HTML:
function GenerateTables() {
var folderz = DocsList.getFolder('SharedVideos');
var contents = folderz.getFiles().sort(function(a,b) {return b.getDateCreated()-a.getDateCreated()});
var file;
var name;
var date;
var url;
var dateModified;
var folder;
var textOutput = "<table>";
textOutput += "<tr><th>File Name</th><th>Create Date</th><th>Modified Date</th></tr>"
for (var i = 0; i < contents.length; i++) {
file = contents[i];
folder = file.getParents()[0];
name = file.getName();
url = "https://docs.google.com/file/d/" +file.getId()+"/preview";
date = Utilities.formatDate(file.getDateCreated(), 'GMT-6', 'MM/dd/yyyy hh:mm:ss aaa');
dateModified = Utilities.formatDate(file.getLastUpdated(), 'GMT-6', 'MM/dd/yyyy hh:mm:ss aaa');
textOutput += "<tr><td>" +name + "</td><td>" + date + "</td><td>" + dateModified + "</td></tr>";
textOutput += "<tr><td colspan='3'>";
textOutput += "<iframe src='"+url+"' height='385' width='640'></iframe>";
textOutput += "</td></tr>";
}
textOutput +="</table>";
return textOutput;
}
function doGet() {
var text = GenerateTables();
return HtmlService.createHtmlOutput(text);
}
The iframe is being converted to
<iframe data-caja-src='[the correct URL]' height="385" width="640"></iframe>
I was hoping it would be a simple process, but the more I got looking into it, the more complicated it seemed to be. Is there an easier way to do what I'm trying to do? I don't have much experience using Caja, but maybe there's a simple way to embed a video using Caja, I just couldn't get anything to work.
There is not yet a way to embed videos inside HtmlService. I think there's a feature request for it on the issue tracker, but regardless it's something we know about.

How to serialize HTML DOM to XML in IE 8?

Is there a way to do it(serialization of HTML DOM into XML) in IE 8 or any other older version of IE.
In firefox :
var xmlString = new XMLSerializer().serializeToString( doc );
does it.I haven't tried it, though.
XMLSerializer causes error in IE 8, that it is not defined.
var objSerializeDOM = {
//Variable to hold generated XML.
msg : "",
serializeDOM : function() {
dv = document.createElement('div'); // create dynamically div tag
dv.setAttribute('id', "lyr1"); // give id to it
dv.className = "top"; // set the style classname
// set the inner styling of the div tag
dv.style.position = "absolute";
// set the html content inside the div tag
dv.innerHTML = "<input type='button' value='Serialize' onClick='objSerializeDOM.createXML()'/>"
"<br>";
// finally add the div id to ur form
document.body.insertBefore(dv, document.body.firstChild);
},
/**
* XML creation takes place here.
*/
createXML : function() {
objSerializeDOM.msg += "";
objSerializeDOM.msg += "<?xml version='1.0' encoding='UTF-8'?>\n\n";
// Get all the forms in a document.
var forms = document.forms;
for ( var i = 0; i < forms.length; i++) {
// Get all the elements on per form basis.
elements = document.forms[i].elements;
objSerializeDOM.msg += "<FORM name=\"" + forms[i].name + "\" method=\""
+ forms[i].method + "\" action=\"" + forms[i].action + "\">\n\n";
for ( var j = 0; j < elements.length; j++) {
objSerializeDOM.msg += " <" + elements[j].tagName + " type=\""
+ elements[j].type + "\"" + " name=\""
+ elements[j].name + "\"" + " Value =\""
+ elements[j].value + "\" />\n";
}
alert(document.forms[i].elements[1].event);
}
objSerializeDOM.msg += "\n\n</FORM>\n\n";
alert(objSerializeDOM.msg);
objSerializeDOM.writeToFile(objSerializeDOM.msg);
},
/**
* Writes the msg to file at pre-specified location.
* #param msg
* the XML file created.
*/
writeToFile : function(msg) {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("c:\\myXML.xml", true);
fh.WriteLine(msg);
fh.Close();
}
};
objSerializeDOM.serializeDOM();
I wrote this JS, I run this javascript using GreaseMonkey4IE. This simply puts a button on every page of the domain you specify in GM4IE. On click of that button it will parse the HTML document and create an XML file. It will also display the same as an alert first and will save the XML in your local drive on path specified.
There a still many improvements I am planning to do, but yes it works and may be give you guys an idea.The program is self-explanatory, I hope.
please have a look here How to get Events associated with DOM elements?Thanks