Methods

appendDomToWorkspace

static

appendDomToWorkspace(xml, workspace) returns Array of string

Decode an XML DOM and create blocks on the workspace. Position the new blocks immediately below prior blocks, aligned by their starting edge.

Parameter

xml

Element

The XML DOM.

Value must not be null.

workspace

Blockly.Workspace

The workspace to add to.

Value must not be null.

Returns

Array of string An array containing new block IDs.

blockToDom

static

blockToDom(block, opt_noId) returns Element

Encode a block subtree as XML.

Parameter

block

Blockly.Block

The root block to encode.

Value must not be null.

opt_noId

Optional

boolean

True if the encoder should skip the block ID.

Returns

non-null Element Tree of XML elements.

blockToDomWithXY

static

blockToDomWithXY(block, opt_noId) returns Element

Encode a block subtree as XML with XY coordinates.

Parameter

block

Blockly.Block

The root block to encode.

Value must not be null.

opt_noId

Optional

boolean

True if the encoder should skip the block ID.

Returns

non-null Element Tree of XML elements.

clearWorkspaceAndLoadFromXml

static

clearWorkspaceAndLoadFromXml(xml, workspace) returns Array of string

Clear the given workspace then decode an XML DOM and create blocks on the workspace.

Parameter

xml

Element

XML DOM.

Value must not be null.

workspace

Blockly.Workspace

The workspace.

Value must not be null.

Returns

Array of string An array containing new block ids.

deleteNext

static

deleteNext(xmlBlock)

Remove any 'next' block (statements in a stack).

Parameter

xmlBlock

Element

XML block element.

Value must not be null.

domToBlock

static

domToBlock(xmlBlock, workspace) returns Blockly.Block

Decode an XML block tag and create a block (and possibly sub blocks) on the workspace.

Parameter

xmlBlock

Element

XML block element.

Value must not be null.

workspace

Blockly.Workspace

The workspace.

Value must not be null.

Returns

non-null Blockly.Block The root block created.

domToPrettyText

static

domToPrettyText(dom) returns string

Converts a DOM structure into properly indented text.

Parameter

dom

Element

A tree of XML elements.

Value must not be null.

Returns

string Text representation.

domToText

static

domToText(dom) returns string

Converts a DOM structure into plain text. Currently the text format is fairly ugly: all one line with no whitespace.

Parameter

dom

Element

A tree of XML elements.

Value must not be null.

Returns

string Text representation.

domToVariables

static

domToVariables(xmlVariables, workspace)

Decode an XML list of variables and add the variables to the workspace.

Parameter

xmlVariables

Element

List of XML variable elements.

Value must not be null.

workspace

Blockly.Workspace

The workspace to which the variable should be added.

Value must not be null.

domToWorkspace

static

domToWorkspace(xml, workspace) returns Array of string

Decode an XML DOM and create blocks on the workspace.

Parameter

xml

Element

XML DOM.

Value must not be null.

workspace

Blockly.Workspace

The workspace.

Value must not be null.

Returns

Array of string An array containing new block IDs.

textToDom

static

textToDom(text) returns Element

Converts an XML string into a DOM structure. It requires the XML to have a root element of . Other XML string will result in throwing an error.

Parameter

text

string

An XML string.

Throws

if XML doesn't parse or is not the expected structure.

Returns

non-null Element A DOM object representing the singular child of the document element.

variablesToDom

static

variablesToDom(variableList) returns Element

Encode a list of variables as XML.

Parameter

variableList

Array of non-null Blockly.VariableModel

List of all variable models.

Value must not be null.

Returns

non-null Element List of XML elements.

workspaceToDom

static

workspaceToDom(workspace, opt_noId) returns Element

Encode a block tree as XML.

Parameter

workspace

Blockly.Workspace

The workspace containing blocks.

Value must not be null.

opt_noId

Optional

boolean

True if the encoder should skip the block IDs.

Returns

non-null Element XML document.