}
});
-session.web.json_node_to_xml = function(node, single_quote, indent) {
+session.web.json_node_to_xml = function(node, human_readable, indent) {
// For debugging purpose, this function will convert a json node back to xml
// Maybe usefull for xml view editor
+ indent = indent || 0;
+ var sindent = (human_readable ? (new Array(indent + 1).join('\t')) : ''),
+ r = sindent + '<' + node.tag,
+ cr = human_readable ? '\n' : '';
if (typeof(node) === 'string') {
- return node;
- }
- else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
+ return sindent + node;
+ } else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
throw("Node a json node");
}
- indent = indent || 0;
- var sindent = new Array(indent + 1).join('\t'),
- r = sindent + '<' + node.tag;
for (var attr in node.attrs) {
var vattr = node.attrs[attr];
if (typeof(vattr) !== 'string') {
vattr = JSON.stringify(vattr);
}
vattr = vattr.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
- if (single_quote) {
+ if (human_readable) {
vattr = vattr.replace(/"/g, "'");
}
r += ' ' + attr + '="' + vattr + '"';
}
if (node.children && node.children.length) {
- r += '>\n';
+ r += '>' + cr;
var childs = [];
for (var i = 0, ii = node.children.length; i < ii; i++) {
- childs.push(session.web.json_node_to_xml(node.children[i], single_quote, indent + 1));
+ childs.push(session.web.json_node_to_xml(node.children[i], human_readable, indent + 1));
}
- r += childs.join('\n');
- r += '\n' + sindent + '</' + node.tag + '>';
+ r += childs.join(cr);
+ r += cr + sindent + '</' + node.tag + '>';
return r;
} else {
return r + '/>';