How to fetch XML with fetch api How to fetch XML with fetch api xml xml

How to fetch XML with fetch api


Using native DOMParser getCurrentCity(location) can be written:

function getCurrentCity(location) {    const lat = location.coords.latitude;    const lon = location.coords.longitude;    return fetch(apis.currentWeather.url(lat, lon))        .then(response => response.text())        .then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))        .then(data => console.log(data))}