/**********************************/ //json from saved search [ { recordType: "job", id: "274", values: { customer: [ { value: "159", text: "Gentry Inc." } ], entityid: "Floor Sanding", jobtype: [ { value: "1", text: "Fixed Price" } ] } }, { recordType: "job", id: "181", values: { customer: [ { value: "159", text: "Gentry Inc." } ], entityid: "Implementation Engagement", jobtype: [ { value: "1", text: "Fixed Price" } ] } }, { recordType: "job", id: "332", values: { customer: [ { value: "159", text: "Gentry Inc." } ], entityid: "LA Office Refurbishment", jobtype: [ { value: "2", text: "Time and Materials" } ] } }, { recordType: "job", id: "273", values: { customer: [ { value: "159", text: "Gentry Inc." } ], entityid: "New Office Fitout", jobtype: [ { value: "2", text: "Time and Materials" } ] } } ] /******************************/ //function to convert json to xml function json2xml(o, tab) { var toXml = function(v, name, ind) { var xml = ""; log.debug({ title: 'v instanceof Array 72', details: v instanceof Array }) log.debug({ title: 'v 76', details: v }) if (v instanceof Array) { for (var i=0, n=v.length; i" : "/>"; if (hasChild) { for (var m in v) { if (m == "#text") xml += v[m]; else if (m == "#cdata") xml += ""; else if (m.charAt(0) != "@") xml += toXml(v[m], m, ind+"\t"); } xml += (xml.charAt(xml.length-1)=="\n"?ind:"") + ""; } } else { log.debug({ title: 'v before second tostring()', details: v }) var str = v + ''; xml += ind + "<" + name + ">" + str + ""; } return xml; }, xml=""; for (var m in o){ log.debug({ title: 'm', details: m }) log.debug({ title: 'o[m]', details: o[m] }) log.debug({ title: 'o', details: o }) xml += toXml(o[m], m, ""); return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, ""); } }