From 6544f023e5168a93b8a183459fea2d5ced66a1d8 Mon Sep 17 00:00:00 2001 From: boyska Date: Sun, 5 Dec 2021 17:39:52 +0100 Subject: [PATCH] FIX document parsing and setting priorities --- radiomanifest.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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) {