[Ionic 4] XML Parsing with XML2JS and HTTP. This Question is for Pro!

IONIC 4 (NOT beta) and it does NOT work for me (In IONIC 3 it is working) What have changed?’

I am trying to parse a XML file from my assets/xml/myfile.xml files…

Is there any other way to parse a XML?

First i thought it was a path problem but tested every path i can use. even moved the file to the root of Home (togheter with home.page.ts files).

My path see image:
d338dd3282135175076db1acd5fbf5de59a0dd06_2_351x499

I am using
XML2Js
@angular/common/http

I used it in Ionic 3 with no problems but i migrating to Ionic v4. And fix one problem after onther.

ERROR: 404 error…

My XML File is located in this folder Assets.
In Ionic 3 it works with the plugin

First of all I import my plugins in Home.page.ts

import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';

In my home.page.ts (For parsing)…

    loadXML()
    {
        this.http.get('/assets/XML/myfile.xml',
      {
        headers: new HttpHeaders()
        .set('Content-Type', 'text/xml')
        .append('Access-Control-Allow-Methods', 'GET')
        .append('Access-Control-Allow-Origin', '*')
        .append('Access-Control-Allow-Headers', "Access-Control-Allow-Headers, Access-Control-Allow-Origin, Access-Control-Request-Method"),
        responseType:'text'
      })
      .subscribe((data)=>
      {
         this.parseXML(data)
         .then((data)=>
         {
            this.xmlItems = data;
         });
      });
    }

If there is a better way to do this tell me also.
I find this a very easy to change update files.

If you answer my question Please write a long answer so i understan not a professional on this area, New at ionic 4.

Or send me a an example so i can test.

Best regards

1 Like

This was the issue here:

npm install --save stream timers

At last found the problem… by help of a professional

Thank you very much for all your help!!

1 Like