How to get xml of blocks

744 views
Skip to first unread message

Sketch

unread,
Jun 26, 2021, 9:33:51 AM6/26/21
to Blockly
Hi all!
I am new so i migth have done something wrong.

Anyways i am trying to add a export/import feature to my workspace.
I used this link to get the XML:

And this is my code for getting the xml:

var xml = Blockly.Xml.workspaceToDom(toolbox);
var xml_text = Blockly.Xml.domToText(xml);

But I keep getting a error in the console log.
Error:
Uncaught TypeError: a.getTopBlocks is not a function
    at Object.Blockly.Xml.workspaceToDom (blockly_compressed.min.js:1017)
    at NjkYzGYKPPzM:517

I have no idea what i am doing wrong.
So if anyone can help me?

Thanks
Luke

Merlin04

unread,
Jun 27, 2021, 7:08:06 PM6/27/21
to Blockly
What is in your toolbox object? Try replacing it with Blockly.getMainWorkspace(), like this: https://github.com/kobra-dev/Kobra/blob/dev/src/components/CodeEditor.tsx#L468

Sketch

unread,
Jun 28, 2021, 2:14:18 AM6/28/21
to Blockly
Hi there.
I've already found a solution to My problem this morning.
Anyways Thanks for replying!

Op maandag 28 juni 2021 om 01:08:06 UTC+2 schreef Merlin04:

amir maalaoui

unread,
Jun 28, 2021, 10:10:03 AM6/28/21
to blo...@googlegroups.com
convert workspace to xml
      var xmlDom = Blockly.Xml.workspaceToDom(workspace);
      var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
console.log(xmlText);

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/2748a9ea-4ae3-4c2b-a990-ba699164393dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages