0

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.

EMM
  • 1,812
  • 8
  • 36
  • 58
  • 1
    @kaylan Perhaps he is unaware of the functionality, and should be given a link that explains the proper way of setting answers for questions? – CS. Jul 18 '11 at 09:35
  • 1
    @CS, it doesn't require any link. Because, any one can know by seeing the TICK mark just below the Answer is used to accept it. And my name is kalyan not kaylan. Please, see the name Before Commenting. – Sai Kalyan Kumar Akshinthala Jul 18 '11 at 09:42
  • 1
    @kalyan You helped more than I realized, by explaining in plain text how to answer a question. Now hopefully this user has now learned how to do it, and that it is very important to mark answers to your questions. If an answer is the answer, you click the tick button. If you never mark tick an answer, you will probably not receive answers in the future. So he should go to all of his questions and tick the answer that helped him with the problem. – CS. Jul 18 '11 at 09:46
  • @kalyan If I get an acceptable answer I will definitely accept it. – EMM Jul 28 '11 at 08:26

1 Answers1

0
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

Community
  • 1
  • 1
EMM
  • 1,812
  • 8
  • 36
  • 58