forked from stsvilik/Xml-to-JSON
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson2xml.min.js
1 lines (1 loc) · 873 Bytes
/
json2xml.min.js
1
!function(window){function lines(str){return str=str.replace(/\r\n/g,"\n")}function makeSafe(str){return str=str.replace(/</g,"<").replace(/&/g,"&"),lines(str)}window.json2xml=function(o){var toXml=function(v,name,ind){var xml="";if(v instanceof Array)for(var i=0,n=v.length;n>i;i++)xml+=toXml(v[i],name,ind+"");else if("object"==typeof v){var hasChild=!1;xml+=ind+"<"+name;for(var m in v)"@"==m.charAt(0)?xml+=" "+m.substr(1)+'="'+v[m].toString()+'"':hasChild=!0;if(xml+=hasChild?">\n":"/>",hasChild){for(var m in v)"#text"==m?xml+=makeSafe(v[m]):"#cdata"==m?xml+="<![CDATA["+lines(v[m])+"]]>":"@"!=m.charAt(0)&&(xml+=toXml(v[m],m,ind+" "));xml+=("\n"==xml.charAt(xml.length-1)?ind:"")+"</"+name+">\n"}}else xml+=ind+"<"+name+">"+makeSafe(v&&v.toString&&v.toString()||"")+"</"+name+">\n";return xml},xml="";for(var m in o)xml+=toXml(o[m],m,"");return xml}}(window);