I'm hitting an interesting problem for Verbosio. Specifically, I can't figure out how to take a XUL file and convert it to a XUL document.
I've considered several ideas so far:
document.implementation.createDocument(XUL_NS, "xul:window", null). Unfortunately, this returns a XMLDocument, not a XULDocument.DOMParser.parseFromString(source, "application/vnd.mozilla.xul+xml"). This won't work because the XUL content-type isn't supported by DOMParser, and besides, it relies on document.implementation.document.cloneNode(false). See bug 42976, which no one's done anything on.Anyone else have good ideas? I really don't want to hack DOMImplementation right now, or implement cloneNode for XULDocument...
Background: This is about the need to edit documents containing XUL widgets (typically XUL documents). I could go with XMLDocument, but the results might be a bit hard to predict. On the other hand, I would want any XUL overlay processing instructions to be present, but not active. So I'm not sure what the right thing to do is here.
UPDATE: Thanks, Mr. Ross! That was yet another trick I did not know about! My quick tests from Venkman shows it works beautifully. There's a lot of interesting code there.
Posted by WeirdAl at September 25, 2005 9:53 PMDo you mean something like this function?
http://faser.net/mab/chrome/content/js/utils.js
/**
* Insert an XML string in a XML/XUL document
*
* @param {XML Element} node
* @param {string} sxml The XML string
* @param {bool} isXul Indicate if the string is a XUL XML
* @param {bool} insertBefore Indicate if the XML should be appended or inserted before the XML element
* @return bool
* Thanks to Zero (zer0.shock@libero.it)
*/
function innerXML(node,sxml,isXUL,insertBefore) {...}
You can create a brand new shiney XULDocument using Components.classes["@mozilla.org/xul/xul-document;1"].createInstance().
(one of the many many things Gecko/layout registers at http://lxr.mozilla.org/seamonkey/source/layout/build/nsLayoutModule.cpp#824)
Posted by: James Ross at September 26, 2005 4:41 AM