[SOLVED] Rule to extract data from XML

Hi, i described my problem in another thread already, but i think, it is better to open a new thread in rules section:

I want to extract the url of the latest mp3-file from this list:

http://www.deutschlandfunk.de/podcast-nachrichten.1257.de.podcast.xml

This is my rule, i already get the url in the log…

rule "Squeezebox DLF Podcast"
when
    System started
then
	var String url = "http://www.deutschlandfunk.de/podcast-nachrichten.1257.de.podcast.xml"
	logInfo ("Squeezebox-DLF", "1 --- Stream URL: " + url)
end

It is not much, but a good beginning :wink:

Can someone help me? In my link above there is an example like it is done in php, but i´m no programmer…

I tried the feed binding, but with this i only get the date and time of the latest feed, not the url of the mp3-file.

The XPATH transform needs to be installed:

rule "Squeezebox DLF Podcast"
when
    System started
then
    val String longurl = "http://www.deutschlandfunk.de/podcast-nachrichten.1257.de.podcast.xml"
    val String url = transform("XPATH", "//channel/item[1]/link/text()", longurl)
    logInfo("Squeezebox-DLF", "1 --- Stream URL: " + url)
end

@vzorglub
Thanks, but this gives me the still longurl into the log.

I think you have a small typing error. “val String url …” --> the last thing in this line has to be longurl inside the brackets, not url?

Is the XPATH transformation service installed?

I have installed ALL transformation services.

Sorry,
Changed it
This works for me:

rule "Squeezebox DLF Podcast"
when
    Item LivingRoom_WallSwitch changed to ON
then
    val String longurl = sendHttpGetRequest("http://www.deutschlandfunk.de/podcast-nachrichten.1257.de.podcast.xml")
    val String url = transform("XPATH", "//channel/item[1]/link/text()", longurl)
    logInfo("Squeezebox-DLF", "1 --- Stream URL: " + url)
end
2 Likes

Yes, thank you!

Now it works!

I also tried it inside an item, but this doesn´t work:

String Feed_DLF_News_url "Titel url [%s]"  { http="<[http://www.deutschlandfunk.de/podcast-nachrichten.1257.de.podcast.xml:30000:XPATH(/channel/item/link)]" }

I will stay with the rule.

That’s because the XPATH is incorrect

String Feed_DLF_News_url "Titel url [%s]"  { http="<[http://www.deutschlandfunk.de/podcast-nachrichten.1257.de.podcast.xml:30000:XPATH(//channel/item[1]/link/text())]" }

1 Like

Cool!
Could you mark the solution, please?
Thanks