JSFiddle - React, Tailwind, and code Playground
JavaScript
var xmlString = '<parent>\
<node1>Some Value1</node1>\
<node2>Some Value2</node2>\
<node3>\
<childNode1>Some Child Value1</childNode1>\
<childNode2>Some Child Value2</childNode2>\
</node3>\
</parent>'
$(document).ready(function() {
var xml = $.parseXML(xmlString);
xml2html($(':root', xml), $('body'));
});
function xml2html(xml, container) {
var tagName = $(xml).get(0).tagName;
var div = $(document.createElement('div'))
.attr({ id: tagName })
.appendTo(container)
if($(xml).children().length == 0) {
div.text($(xml).text());
}
else {
$(xml).children().each(function(index, node) {
xml2html(node, div);
});
}
}