Created
October 27, 2023 16:32
-
-
Save upalexgill/12f6bbd80fe635546b3f0f9818695665 to your computer and use it in GitHub Desktop.
Parse XML data to string array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const xmlData = ``; | |
| function getCommaSeparatedUrls(xml) { | |
| const parser = new DOMParser(); | |
| const xmlDoc = parser.parseFromString(xml, 'text/xml'); | |
| const sitemapNodes = xmlDoc.getElementsByTagName('loc'); | |
| const urls = []; | |
| for (let i = 0; i < sitemapNodes.length; i++) { | |
| urls.push(sitemapNodes[i].textContent); | |
| } | |
| return urls.join(','); | |
| } | |
| const commaSeparatedUrls = getCommaSeparatedUrls(xmlData); | |
| const urlArray = commaSeparatedUrls.split(','); | |
| console.log(urlArray); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment