Help needed with XML parser
Added by Michael Hansen over 8 years ago
Hi,
I am trying to parse the following xml file to get the video infos and urls:
http://www.3sat.de/mediathek/rss/mediathek.xml
I tried it the way the wiki is describing it:
var doc = showtime.httpReq(BASE_URL+'mediathek.xml').toString();
doc = doc.replace(/media:/g,"media_");
var chan = XML.parse(doc);
showtime.trace("channel: " + chan.channel);
for (var i in chan.item) {
var video_url = chan.item[i].enclosure["@url"];
page.appendItem(video_url, 'video', {
station: chan.item[i].title,
title: chan.item[i].title,
description: chan.item[i].description,
icon: chan.item[i].media_group.media_thumbnail["@url"],
album_art: chan.item[i].media_group.media_thumbnail["@url"],
album: '',
duration: 1234,
genre: chan.item[i].media_group.media_category,
});
};
But the result is always 'undefined'
Can someone please help me to parse this xml?
Maybe it is too big?
Thank you,
druelie
Replies (7)
RE: Help needed with XML parser
-
Added by Leonid Protasov over 8 years ago
You need to do it with filterNodes.
RE: Help needed with XML parser
-
Added by Michael Hansen over 8 years ago
yes, I have tried that already, but with the same result.
Can you give an example for that xml please?
Thx druelie
RE: Help needed with XML parser
-
Added by Leonid Protasov over 8 years ago
Michael Hansen wrote:
yes, I have tried that already, but with the same result.
Can you give an example for that xml please?Thx druelie
Sure:
var doc = showtime.httpReq(unescape(url) + '/web/getservices?sRef=' + serviceReference); page.loading = false; doc = XML.parse(doc); var e2services = doc.e2servicelist.filterNodes('e2service'); for (var i = 0; i < e2services.length; i++) { page.appendItem(plugin.getDescriptor().id + ":zapTo:" + url + ':' + escape(e2services[i].e2servicename) + ':' + encodeURIComponent(e2services[i].e2servicereference), "video", { title: e2services[i].e2servicename }); }
RE: Help needed with XML parser
-
Added by Michael Hansen over 8 years ago
thx, from which of your plugins is this, so I can see the full code?
RE: Help needed with XML parser
-
Added by Leonid Protasov over 8 years ago
Michael Hansen wrote:
thx, from which of your plugins is this, so I can see the full code?
It's from enigma2 but looks like I can just fix your code. Do:
var doc = showtime.httpReq(BASE_URL+'mediathek.xml').toString(); doc = doc.replace(/media:/g,"media_"); var doc = XML.parse(doc); showtime.trace("channel: " + doc.channel); var items = doc.channel.filterNodes('item'); for (var i = 0; i < items.length; i++) { var video_url = items[i].enclosure["@url"]; page.appendItem(video_url, 'video', { station: items[i].title, title: items[i].title, description: items[i].description, icon: items[i].media_group.media_thumbnail["@url"], album_art: items[i].media_group.media_thumbnail["@url"], album: '', duration: 1234, genre: items[i].media_group.media_category, }); };
Enjoy
RE: Help needed with XML parser
-
Added by Michael Hansen over 8 years ago
no, that is exactly what I have tried, but it does not work
RE: Help needed with XML parser
-
Added by Leonid Protasov over 8 years ago
Michael Hansen wrote:
no, that is exactly what I have tried, but it does not work
page.loading = true; var XML = require('showtime/xml'); var doc = showtime.httpReq('http://www.3sat.de/mediathek/rss/mediathek.xml').toString().replace(/media:/g, 'media_'); doc = XML.parse(doc); var items = doc.rss.channel.filterNodes('item'); for (var i = 0; i < items.length; i++) { page.appendItem(items[i].enclosure["@url"], 'video', { title: items[i].title, description: items[i].description, icon: items[i].media_group.media_thumbnail["@url"], genre: items[i].media_group.media_category }); }; page.loading = false;
(1-7/7)