Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML namespace #1978

Closed
NeilFraser opened this issue Jul 17, 2018 · 2 comments
Closed

XML namespace #1978

NeilFraser opened this issue Jul 17, 2018 · 2 comments

Comments

@NeilFraser
Copy link
Contributor

NeilFraser commented Jul 17, 2018

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.

@jollytoad
Copy link
Contributor

Selecting an alternative namespace would be highly desirable from our point of view - we are currently processing the blockly xml files in Java, and have to deliberately fiddle with the xml ns decl beforehand.

It would also be useful for other development processes, hand editing/viewing of the xml files - I work in IntelliJ IDEA which complains bitterly about the abuse of the html namespace ;)

We'd be able to provide a schema of some kind for XML too if able to set the namespace to help with manual viewing/editing, and allow validation against it.

I'd be happy to contribute towards this effort if it's deemed to be a direction you want to go.

@rachel-fenichel rachel-fenichel added this to the Backlog milestone Aug 7, 2018
@AnmAtAnm AnmAtAnm removed this from the Backlog milestone Dec 11, 2018
NeilFraser added a commit that referenced this issue Jul 2, 2019
NeilFraser added a commit that referenced this issue Jul 8, 2019
@NeilFraser
Copy link
Contributor Author

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants