JavaScript DOM Parser incompatible with document?

1

My idea with DOM Parser was to load HTML layouts, put them in a single element, and then use them when needed. But in tests, the object generated by DOMParser is not added to the document. Here's the example I did in JSFIddle:

HTML:

<div id="resHtml">
</div>
<div id="resDOM">
</div>
<div id="resXML">
</div>

JavaScript

var txt = '<fieldset><legend>Em texto HTML</legend><p>Alguma coisa a dizer</p></fieldset>';
document.getElementById("resHtml").innerHTML = txt;
// Simples, mas aí tenho que já ter em texto, e não dentro de um XML.
var domDoc = document.createElement('fieldset');
var domLegend = document.createElement('legend');
domLegend.innerHTML = 'Em DOM';
var domTexto = document.createElement('p');
domTexto.innerHTML = 'Alguma coisa a dizer';
domDoc.appendChild(domLegend);
domDoc.appendChild(domTexto);
document.getElementById("resDOM").appendChild(domDoc);
// Esse é construído peça por peça, não serve, mas ilustra o appendChild
var str = '<fieldset><legend>Em XML</legend><p>Alguma coisa a dizer</p></fieldset>';
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(str,"text/xml");
//document.getElementById("resXML").appendChild(xmlDoc); NÃO FUNCIONA!
// É um exemplo simples, mas posso ter por exemplo uma coleção de formulários em um XML e pegar só que eu preciso adicionando por appendChild.
// Mas não funciona, então é o seguinte...
document.getElementById("resXML").innerHTML = (new XMLSerializer()).serializeToString(xmlDoc);

In the end, I have to serialize, which may even slow down a page depending on the problem.

In Mozilla's MDN ( Reference ) it is as experimental, so my question is the following: Is this API compatible any day, should we invest in it, or is there a fundamental difference between the objects we have to keep in mind?

    
asked by anonymous 19.06.2017 / 15:39

0 answers