Value of a string-Item from xml-file via XPath

Tags: #<Tag:0x00007f61706add70> #<Tag:0x00007f61706adc58> #<Tag:0x00007f61706adb40>

Dear all,

i want to transform current Song-Title, Artist and Album from an autogenerated xml-file:

<?xml version="1.0" encoding="UTF-8"?>

<now_playing playing="1" timestamp="2016-10-28T12:59:41Z">
	<song timestamp="2016-10-28T12:59:40Z">
		<title>Salva Mea</title>
		<artist>Faithless</artist>
		<album>Salva Mea</album>
		<genre>Dance</genre>
		<kind>MPEG-Audiodatei</kind>
		<track>1</track>
		<numTracks>1</numTracks>
		<year>1996</year>
		<comments></comments>
		<time>226</time>
		<bitrate>256</bitrate>
		<disc>1</disc>
		<numDiscs>1</numDiscs>
		<playCount>2</playCount>
		<compilation>No</compilation>
		<urlAmazon/>
		<urlApple>https://itunes.apple.com/us/album/salva-mea/id263689576?i=263689894&amp;uo=4&amp;partnerId=11&amp;at=11lp2h</urlApple>
		<imageSmall/>
		<image/>
		<imageLarge/>
		<composer></composer>
		<grouping></grouping>
		<file></file>
		<artworkID>6e005f4de1b24bab7e34dcdc0ccd59e6</artworkID>
	</song>
</now_playing>

i tried this with the following .items-file:

String 21_Title "Title [%s]"  { http="<[http://192.xxx.xxx.xx:8080/static/iTunes/now_playing.xml:30000:XPATH(/now_playing/song[1]/title)]" }
String 21_Artist "Artist [%s]"  { http="<[http://192.xxx.xxx.xx:8080/static/iTunes/now_playing.xml:30000:XPATH(/now_playing/sing[1]/artist)]" }
String 21_Album "Artist [%s]"  { http="<[http://192.xxx.xxx.xxx:8080/static/iTunes/now_playing.xml:30000:XPATH(/now_playing/song[1]/album)]" }

but nothing happens (XPath Transformation are installed), not even an error in the log as i got when i tried to write a xslt-Transformation.

Unfortunately the XPath-Transformationof oH1 or oH2 isn’t documented everywhere - i found only this in the wiki:

Do anybody works with oH2, XML-Files und XPATH-Transformation and can give me a working example?

Regards,
Heiko

I have been using XSLT, though I suppose I could be using XPATH for all but one of mine.

In XSLT though the path starts with “//”, not just “/”. I’m really digging down in my memory and can’t remember why I needed to do that. You can give it try and see if that works.

Usually, at least with the XSLT, I’ll get an error in the log if the path is wrong so I’m not sure this will help.

Thank you for your reply.

Meanwhile i found out the the autogenerated XML of the iTunes-plugin did not deliver valid xml. To cut the output was the solution to get the current title to my oH2-Item:

<now_playing>
	<song>
		<title>Enjoy the silence</title>
	</song>
</now_playing>

That is my working .item with XPath:

String 21_Title "Titel [%s]"  { http="<[http://192.xxx.xxx.xx:8080/static/now_playing.xml:30000:XPATH(/now_playing/song/title)]" }

And here is the expected change in the log:
23:26:42.136 [INFO ] [marthome.event.ItemStateChangedEvent] - 21_Title changed from Whiskey and Pills to Enjoy the silence

Now i have to find a good solution to deliver current tracks from iTunes to oH2, meanwhile im very impressed about the possibilities of XPath inside oH2 :smile:

1 Like