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 sent authorized header attribute value using c# .net httpclient for third party api call of oauth 2.0

How to sent authorized header attribute value using C# .NET HTTP client for third party API call of OAuth 2.0 For call token From Authorized...

Popular Posts