I am trying to restore or generate a block with the XML code on a button click and set it to my workplace. But it does not work properly, somehow it ain't showing nothing. Help will be appreciated. I have tried the following links:
2.https://embed.plnkr.co/XIeR0L/
3.https://developers.google.com/blockly/guides/create-custom-blocks/blockly-developer-tools
4.https://developers.google.com/blockly/guides/get-started/web
My code to restore:
value = data[5];
alert(value );
Blockly.Xml.appendDomToWorkspace(value ,demoWorkspace);
I have also tried in the following way:
var xml = Blockly.Xml.textToDom(data[5]);
Blockly.Xml.domToWorkspace(xml, demoWorkspace);
Block restore function:
function restore() {
$.ajax({
type: "GET",
url: "/save_composition",
content_type : "application/json",
success: function(data) {
value = data[5];
{#console.log(value.replace(/['"]+/g, ''));#}
var result = value.slice(1, -1);
alert(result);
var xml = Blockly.Xml.textToDom(data[5]);
Blockly.Xml.domToWorkspace(xml, demoWorkspace);
},
error: function(xhr, textStatus) {
alert(textStatus);
}});
}
A single response of XML is:
<xml xmlns="http://www.w3.org/1999/xhtml">
<variables></variables>
<block type="controls_repeat_ext" id="J]k6G0~I).TfgP_;:j=S" x="223" y="65">
<value name="TIMES">
<block type="math_number" id="j{Y2o]x%v(R#1#V*xm)0">
<field name="NUM">10</field>
</block>
</value>
<statement name="DO">
<block type="print_content" id="}$v5G?]mBm(R^8)sri-L">
<value name="to_print">
<block type="text" id="esg1;Q4KV$g;^Ul?BF]p">
<field name="TEXT">test</field>
</block>
</value>
</block>
</statement>
</block>
</xml>