@ou-imdt/utils
Version:
Utility library for interactive media development
14 lines (13 loc) • 521 B
JavaScript
import fetchText from './fetchText.js';
/**
* Fetches a resource and parses it as an XML document.
* @param {string} url - The URL of the resource to fetch.
* @returns {Promise<Element>} A promise that resolves to the document element of the parsed XML.
*
* @requires {DOMParser} - Required to parse XML content.
*/
export default async function fetchXML(url) {
const contents = await fetchText(url);
const document = new DOMParser().parseFromString(contents, 'text/xml');
return document.documentElement;
}