diff --git a/radiomanifest.js b/radiomanifest.js index ebdbf38..2fc20d5 100644 --- a/radiomanifest.js +++ b/radiomanifest.js @@ -34,11 +34,12 @@ class Radio { } static fromDOM (xml) { - let res = xml.evaluate('/radio-manifest/streaming/source', xml) + const doc = xml.cloneNode(true) + let res = doc.evaluate('/radio-manifest/streaming/source', doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) const sources = [] - while (true) { - const src = res.iterateNext() - if (src === null) break + for (let i = 0; i < res.snapshotLength; i++) { + const src = res.snapshotItem(i) + if (!src.hasAttribute('priority')) { src.setAttribute('priority', '0') } else if (parseInt(src.getAttribute('priority'), 10) < 0) { @@ -50,7 +51,7 @@ class Radio { return parseInt(a.getAttribute('priority', 10)) < parseInt(b.getAttribute('priority', 10)) }) - res = xml.evaluate('/radio-manifest/schedule', xml) + res = doc.evaluate('/radio-manifest/schedule', doc) const scheduleEl = res.iterateNext() let schedule = null if (scheduleEl !== null) {