renciso218 / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

XMLSerializer and document.createElement problem #88

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Take a block which implements mutator functionality (and is present in the 
code demo, e.g. procedured_defnoreturn)
2. Navigate to the mutationToDom function
3. Add the following lines:
var example = document.createElement('param');
container.appendChild(example);
container.appendChild(example);
4. Select the manipulated block and open the xml tab

What is the expected output? What do you see instead?
The expected output is, that all tags are shown as 'Expected' that means fully 
with the opening (<>) and closing (</>) part of the tag. 

Observed is the following:
chrome: 
<xml>
  <block type="procedures_defnoreturn" x="1" y="1">
    <mutation>
      <param>
      </mutation>
      <title name="NAME">procedure</title>
    </block>
  </xml>

As can be seen </param> is missing and the indentation is also wrong

firefox:
<xml xmlns="http://www.w3.org/1999/xhtml">
  <block type="procedures_defreturn" inline="false" x="123" y="130">
    <mutation>
      <param />
      </mutation>
      <title name="NAME">procedure</title>
    </block>
  </xml>

As can be seen here an additional / is added at the end of param. But the 
second Child is missing (as well as all following)

Similar happens if br, etc. are used.

What browser are you using?
Chromium-browser 18 and Firefox 15 (taken from Ubuntu Software Center)
Ubuntu version: 11.10 

Please provide any additional information below.
It seems that the XMLSerializer has problems with lots of variables, which are 
equal oo html tags.

Why is it a problem at all? It may isn't a problem at the moment, but I  would 
like to generate xml code and some tags are param or similar and work quite 
fine with the original code. There is no way in changing the name into another, 
because i just use it and haven't produced it. 

Additionally, if one day another user would like to add a tag he/she may wants 
to use a xml tag name even if it is also an html tag name. 

By the way: If an createElement entry is added directly behind the xml element 
in core/xml.js (workspaceToDom) the effect is the same. 

I have no suggestion, because I don't know where exactly the problem is and how 
to make sure, that html tags are escaped and taken as given.

p.s. Even if there is no need to fix this in Blockly, it would be nice if you 
could provide some suggested solutions. 

best regards
Marc  

Original issue reported on code.google.com by borntob...@googlemail.com on 9 Nov 2012 at 8:07

GoogleCodeExporter commented 8 years ago
There are several unrelated issues here:

1. Inconsistent trailing slash.  The trailing slash is optional on void 
elements:
http://stackoverflow.com/questions/1946426/html-5-is-it-br-br-or-br
As such, the following code generates a slash in Firefox and none in Chrome:
new XMLSerializer().serializeToString(document.createElement('param'))
Both are acceptable and legal.

2. Only one param added.  This one is your fault.  Try this instead:
  var example1 = document.createElement('param');
  container.appendChild(example1);
  var example2 = document.createElement('param');
  container.appendChild(example2);
The appendChild function does not clone the element.

3. Bad indentation.  This one is my fault.  Blockly.Xml.domToPrettyText is 
pretty ghetto; it's a non-rigourous cosmetic function that isn't smart enough 
to get the indentation of void elements correct. I've made changes (r507) that 
fix the indentation when void elements have a trailing slash.  It still gets it 
wrong where there is no trailing slash.

Original comment by neil.fra...@gmail.com on 11 Nov 2012 at 2:00

GoogleCodeExporter commented 8 years ago
hm okay.

2. If i append two separated children i still only see <param>. For HTML it may 
be a valid and legal tag, but I would like to have xml code. And within this 
xml code i need a <param> </param> block where several more children are 
within. When i use params it works perfectly fine. 

So even as you have mentioned in 1. the command/tag is valid my generated code 
will not work because of errors in the interpreting process. 

One final question. If the block tag would be such a void element, would 
blockly then  behave properly?

e.g.
<xml>
 <block ... >
   <mutation ... ></mutation>
   <title ...></title>
   <block ...>
     <...>   
   <xml>

?? 

I hope I could make clear what i meant in the first place. 

For HTML this is may valid, but the requirement for the xml code that i would 
like to have is that leading and ending 'element' are existent and frame child 
elements etc.

As said before at the moment is no problem for Blockly, because the chosen tag 
names are unequal to the void elements (e.g. block, mutation, etc.).

Original comment by borntob...@googlemail.com on 11 Nov 2012 at 11:48