function DOM2JSON(node) { var obj = {}; obj['tag'] = node.nodeName; obj['children'] = []; var child = node.children; for (var i = 0; i < child.length; i++) { obj['children'].push(DOM2JSON(child[i])) } return obj; }