-
Notifications
You must be signed in to change notification settings - Fork 3.8k
XML namespace #1978
Description
Currently all XML nodes (block, shadow, field, mutation, variables, variable, comment, and probably a few others) are created with document.createElement (either explicitly, or via goog.dom.createDom).
This creates HTML elements, and such inherit a bunch of unexpected properties and methods, some with magical side-effects. The solution to this would be to use a namespace for our XML:
https://developer.mozilla.org/en-US/docs/Web/API/Document/createElementNS
To demonstrate:
var b = document.createElement('block'), i = 0; for (n in b) i++;
-> 233
var b = document.createElementNS('blockly', 'block'), i = 0; for (n in b) i++;
-> 137
And the above example is using a node name that doesn't exist in HTML ('block'). There are even more properties on nodes that do exist in HTML (e.g. 'img').
This should probably be investigated prior to work to remove goog.dom from the codebase (as part of the Closure removal process) and before we switch to passing around XML nodes rather than strings of XML (such as Blockly.Variables.generateVariableFieldXmlString).
Another factor that needs to be considered is Node.js' inability to call document.createElement or document.createElementNS since there's no document object. We need a cross-platform method of creating XML elements.