Marson,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<script>
var someTree = {
tagName: "table",
subTags: [{
tagName: "tr",
subTags: [{
tagName: "td",
text: "some text"
}, {
tagName: "td",
text: "some text 2"
}]
}],
attrs: {
border: 1
}
};
function createElem(tagName, attrs, text) {
var elem = document.createElement(tagName);
if (attrs)
for (var name in attrs) elem.setAttribute(name, attrs[name]);
if (text) elem.textContent = text;
return elem
}
function walker(tree) {
var tagName = tree.tagName,
attrs = tree.attrs,
text = tree.text,
elem = createElem(tagName, attrs, text);
if (tree.subTags) tree.subTags.forEach(function(el) {
el = walker(el);
elem.appendChild(el)
});
return elem
}
var table = walker(someTree);
document.body.appendChild(table);
</script>
</body>
</html>