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

1 comment:

  1. Merkur | Merkur Casino - Best Price Guarantee
    The Merkur Merkur is a compacted and 메리트 카지노 가입코드 fully bet365 adjustable titanium tubing 2-piece double edge razor. Merkur Safety Razor Review: This 샌즈 카지노 게임 Merkur Safety Razor is 바카라 사이트 a must own.

    ReplyDelete

Thank You For Your Great Contribution

Featured Post

How to integrate okta with react / Implementing Okta authentication in a React app

 How to integrate okta with react /  Implementing Okta authentication in a React app for demo please follow  my git repo 1).Before starting ...

Popular Posts