I think the issue you have is not with parsing XML here, but in how you access the URL from within ionic/angular app.
I simplified the code example you have to this:
this.http.get('http://www.gazetaexpress.com/rss/sport/?xml=1').subscribe(data => {
console.log(data);
}, error => {
console.log(error);
});
Now added it as a method to ionViewDidLoad in this stackblitz:
https://stackblitz.com/edit/ionic-4qbega
The error you are getting based on this context is this one:
HttpErrorResponse {headers: {…}, status: 0, statusText: "Unknown Error", url: null…}
error: ProgressEvent
headers: HttpHeaders
message: "Http failure response for (unknown url): 0 Unknown Error"
name: "HttpErrorResponse"
ok: false
status: 0
statusText: "Unknown Error"
url: null
__proto__: HttpErrorResponse
So to fix just data intake you need to do the following:
- use https URL
- also use responseType: 'text'
Code:
this.http.get('https://www.gazetaexpress.com/rss/sport/?xml=1', {responseType: 'text'}).subscribe(data => {
console.log(data);
}, error => {
console.log(error);
});
Now to make this work with your code, it should be something like this:
this.http.get('https://www.gazetaexpress.com/rss/sport/?xml=1', { responseType: 'text'}).subscribe(data => {
this.xmlItems = data;
console.log("data:"+data);
xml2js.parseString(this.xmlItems, function (err, result) {
console.log(result);
});
}, error => {
console.log(error);
});
PS: also check this good article here in case you have more q: https://www.ionicrun.com/transform-xml-to-json-in-ionic-2-with-angular-4-3/