JSFiddle - React, Tailwind, and code Playground
HTML
<body onload="process()">
<div id="import"></div>
<div id="adopt"></div>
</body>
JavaScript
var xmlData = "xml=<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><select><option value=\"1\">A</option></select>&delay=3";
xmlData = "xml=<select><option value=\"1\">A</option></select>";
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject() {
var xmlHttp;
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHttp;
}
function process() {
if (xmlHttp) {
try {
xmlHttp.open("POST", "/echo/xml/", true);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.send(xmlData);
} catch (e) {
alert("In process function.<br/>Error in creating xmlHttp object: " + e.toString());
}
}
}
function handleStateChange() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
try {
handleResponse();
} catch (e) {
alert("handleResponse errored." + e.toString());
}
} else {
alert("State = " + xmlHttp.readyState + " Status= " + xmlHttp.status);
}
}
}
function handleResponse() {
var xmlResponse = xmlHttp.responseXML,
root = xmlResponse.documentElement;
console.log(xmlHttp.responseText);
var i = document.importNode(root, true);
var a = document.adoptNode(root);
document.getElementById("import").appendChild(i);
document.getElementById("adopt").appendChild(a);
}