in my app i am trying to load XML file in order to use his data.
but i am facing an error in Chrome browser console:
{error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at XMLHttp…,
service.ts
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class ReadDataService {
headers = new HttpHeaders({ 'Content-Type': 'text/xml' });
xml: string;
private _url: string = "../../assets/sf9_commandpacket.xml";
constructor(private _http:HttpClient) {}
getData(): Observable<string> {
return this._http.get<string>(this._url, { headers: this.headers });
}
}
}
i see in the error, that he is trying to load json, why?
I tried to implement this solution:
this._http.get(this._url, { headers: this.headers, responseType: text / xml }).subscribe(response => { return response; })


HttpClient.get()by default returns JSON if you are requesting non-JSON data you need to useresponseType:'text'option as mentioned in one of the link I have sharedthis._http.get(this._url, { responseType: ' text' }).subscribe(response => { console.log(response); });Give this a try and temme what you see