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 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