how to convert json to xml in angular

 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[propinstanceof Array ? '' : "<" + prop + ">";
      if (obj[propinstanceof 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[propinstanceof Array ? '' : "</" + prop + ">";
    }
    var xml = xml.replace(/<\/?[0-9]{1,}>/g'');
    return xml
  }

and finally download json into file 

 downloadXMLFile(xmltradeID) {
    const blob = new Blob([xml], { type: 'application/xml;charset=UTF-8' });
    FileSaver.saveAs(blobtradeID + '.xml');

  }




No comments:

Post a comment

Thank You For Your Great Contribution

Featured Post

how to find duplicate item from array using multiple object keys in angular or javascript

 how to find duplicate item from array using multiple object keys There is a way to find based of multiple key find duplicate records in ang...

Popular Posts