Firefox extension - Create new blank XML DOM object
I'm working on a Firefox extension which includes exporting data into a XML file
So, how do I create a new blank DOM document object via a component service in which I could write all my data before serializing it into XML with 开发者_运维技巧Cc["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(Ci.nsIDOMSerializer).serializeToString(dom);
Alexander
var dom = document.implementation.createDocument("", "", null);
var el = document.createElement("some");
el.setAttribute("key" , "value" );
dom.appendChild( el );
This "dom" object should be a simple example for what you want. For more detail, please refer here https://developer.mozilla.org/en/How_to_create_a_DOM_tree
EDIT,
add way to access the document object in Components scope.
Components.classes["@mozilla.org/xul/xul-document;1"].getService(Components.interfaces.nsIDOMDocument)
This is the "document" XPCOM object, you can just use it with above code. For a interface list, please refer here http://doxygen.db48x.net/mozilla/html/interfacensIDOMDocument.html
精彩评论