How to Create xml file and download it or convert into base64 string

 How to Create xml file and download it or convert into base64 string


1).First Install Following packages from Node module
1).npm install xml-writer
page Url:https://www.npmjs.com/package/xml-writer
2).npm install file-saver --save
page Url:https://www.npmjs.com/package/file-saver
Code Writing:-


import * as XMLWriter from 'xml-writer';
import * as FileSaver from 'file-saver';

import { Injectable } from '@angular/core'; @Injectable({
providedIn: 'root', }) export class HeroService { constructor() { }
generateXml(data,type,IsGenerate){

var XMLWriter = require('xml-writer');
xw = new XMLWriter;
xw.startElement('root').writeAttribute('foo', 'value')
.text('Some content');

if (IsGenerate) { const blob = new Blob([this.xw], { type: 'application/xml;charset=UTF-8' }); FileSaver.saveAs(blob, paramData.ReferenceNo + '.xml'); return ''; } else { return this.xw.output; }

}
}
Now Need to Call Service in Your Component:-
postJson.XMLString = btoa(this.dealFastXMLService.generateXml(this.trademodel, true, false));

No comments:

Post a comment

Thank You For Your Great Contribution

Featured Post

How to remove multiple item from FormArray

 How to remove multiple item from FormArray Call Method at any component :- this.removeItems(formArray, formcontrolCountryID, 2);  Meth...

Popular Posts