I am really sorry, but reading the XPATH introduction and browsing some example code I am still not getting it ... I am working to read data from my VDR system to enrich the plugin I started.
Now my issue is to access the values in the param nodes. I tried a lot with ./param[@name='name'] or /param/text() or combination of both. My guess I simply was not able to get from the docs how to do this ...
Could anyone give me a hint please? Thank would be really great.
You were almost there, I think you just need to combine the methods. You would probably want something like (assuming you're already looping through the each //channel):
./param[@name='name']/text()
That's very "dumbed down" but should give you a starting point. You will probably want to be looping through all the channels and then reading each param accordingly using the above approach. The method above will find a specific param and then should show the text() value of it. This is just off the top of my head, I didn't actually test ...
for channel in xml.xpath(’//a:channel’, namespaces=NAMESPACES):
name = channel.xpath(’./a:param[@name=“name”]’, namespaces=NAMESPACES)
channel_id = channel.xpath(’./a:param[@name=“channel_id”]’, namespaces=NAMESPACES)
I guess the Namespace stuff was really what I was missing. Now I figure that I really did not get Python yet with how loops and so on work properly... For my understanding of your suggestion, Sander:
for channel in xml.xpath('//a:channel', namespaces=NAMESPACES):
Translates to: for each "channel"-node returned by the xpath query, right?
I guess I need some more example-reading on how this works ;-))
However, this was the right pin-point guess and let's see how I can get this to work during the next evenings.
Now I figure that I really did not get Python yet with how loops and so on work properly... For my understanding of your suggestion, Sander:
for channel in xml.xpath('//a:channel', namespaces=NAMESPACES):
Translates to: for each "channel"-node returned by the xpath query, right?
Hello Alex,
Yes, that is correct. You can give the variable used in the for loop a different name if you like, but I usually stick with the name of the node or something similar.
But first - I am getting really far by now, Channellogos, etc .. all works pretty fine.
When I receive EPG data for a current TV event the XML contains it like this:
164826
Monitor
Berichte zur Zeit
Genre: Politik Kategorie: Information Land: D Jahr: 2014 MONITOR will Hintergrund liefern, Diskussionen anstoßen, Themen setzen. Unsere Handschrift: seriöse Information, gepaart mit einer sorgfältigen Analyse. Kritischer, investigativer Journalismus wird in der Redaktion großgeschrieben. "Wir bringen Bewegung in die öffentliche Diskussion und wollen unbequem sein. Wir teilen nach allen Seiten aus", so beschreibt Sonia Seymour Mikich die Aufgabe von MONITOR. Sie leitet die Redaktion seit Januar 2002. Unsere sachlich-nüchterne und kritische Berichterstattung ist seit über 40 Jahren gefragt. Moderator: Georg Restle Altersempfehlung: ab 0 Audio: Stereo Zweikanal Flags: [PrimeTime] [Untertitel] Quelle: DVB/EPGDATA
C-41985-1051-11100
Das Erste HD
1389300300
1800
78
16
0
1389300300
1
false
false
however, the string extracted by xpath seems to be "corrupted" (I assume this is an encoding issue):
[u'Genre: Politik
Kategorie: Information
Land: D
Jahr: 2014
MONITOR will Hintergrund liefern, Diskussionen ansto\xdfen, Themen setzen. Unsere Handschrift: seri\xf6se Information, gepaart mit einer sorgf\xe4ltigen Analyse. Kritischer, investigativer Journalismus wird in der Redaktion gro\xdfgeschrieben. “Wir bringen Bewegung in die \xf6ffentliche Diskussion und wollen unbequem sein. Wir teilen nach allen Seiten aus”, so beschreibt Sonia Seymour Mikich die Aufgabe von MONITOR. Sie leitet die Redaktion seit Januar 2002. Unsere sachlich-n\xfcchterne und kritische Berichterstattung ist seit \xfcber 40 Jahren gefragt.
Moderator: Georg Restle
Altersempfehlung: ab 0
Audio: Stereo Z…
I tried using the encoding=UTF-8 parameter with XML.ElementFromUrl, but that did not help. I could of course manually replace all kinds of substrings - but isn't this a common issue with a common solution ?
An xpath query will always return a list, even if there's just 1 item to return, so you need to always add the [0] (I see I forgot to put that in my example code posted earlier). The u' means it's a unicode string.
is a newline and the \xXX are unicode encoded characters, which should not be a problem at all and be displayed correctly in Plex clients.