N
N
Natalia252017-06-25 23:48:38
Parsing
Natalia25, 2017-06-25 23:48:38

How to unload data from XML file in Angular2 and process it with x2js?

I have an XML file that I'm trying to dump data from - first just text and then a JSON object using x2js

clickHandler() {
    let headers = new Headers();
    headers.append('Content-Type', 'text/xml');


    let text = '';
    this.http.get('./xml/text')
      .map((res: Response) => res.text()).subscribe(data => text = data);

    const x2js = new X2JS();
    const jsonObj = x2js.xml2js(xml);
    let parseString = require('xml2js').parseString;
    let xml = text; //?? 

    parseString(xml, function (err: any, result: any) {
     alert(result); }}

Can you please tell me how to accomplish this task?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question