how to convert json to xml in angular
var obj={'name':raj,'address':{'add':'skg'}}
JsontoXML(obj) {
var xml = '';
for (var prop in obj) {
xml += obj[prop] instanceof Array ? '' : "<" + prop + ">";
if (obj[prop] instanceof Array) {
for (var array in obj[prop]) {
xml += "<" + prop + ">";
xml += this.JsontoXML(new Object(obj[prop][array]));
xml += "</" + prop + ">";
}
} else if (typeof obj[prop] == "object") {
xml += this.JsontoXML(new Object(obj[prop]));
} else {
xml += obj[prop];
}
xml += obj[prop] instanceof Array ? '' : "</" + prop + ">";
}
var xml = xml.replace(/<\/?[0-9]{1,}>/g, '');
return xml
}
and finally download json into file
downloadXMLFile(xml, tradeID) {
const blob = new Blob([xml], { type: 'application/xml;charset=UTF-8' });
FileSaver.saveAs(blob, tradeID + '.xml');
}
I wish for the great of success in all of our destiny endeavors web design agencies in new york
ReplyDelete