Skip to content

Instantly share code, notes, and snippets.

@theJinxrat
Created March 8, 2021 21:26
Show Gist options
  • Save theJinxrat/adc7ae839247956e13d98f96e92765a6 to your computer and use it in GitHub Desktop.
Save theJinxrat/adc7ae839247956e13d98f96e92765a6 to your computer and use it in GitHub Desktop.
Parse RSS file to JSON with Vanilla JS
const items = []
fetch('https://example.com/feed.xml')
.then(res => res.text())
.then(str => new window.DOMParser().parseFromString(str, "text/xml"))
.then(data => {
data.querySelectorAll("item").forEach((item, idx) => {
const obj = {}
Array.from(item.children).map(v => obj[v.tagName] = v.textContent)
items[idx] = obj
})
})
.catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment