This page last changed on Oct 17, 2013 by jasonc.

Hi I am trying to control mythtv using their services api http://www.mythtv.org/wiki/Frontend_Service but am having trouble working out the xpath to use to get the information out of the returned xml.
This is what is returned by the GetStatus command:

<FrontendStatus version="1.0" serializerVersion="1.1">
<State>
<String key="behindtime"/>
<String key="chanid">34750</String>
<String key="chapteridx">1</String>
<String key="description">0:25:25 of 1:02:25</String>
<String key="playedtime">0:25:25</String>
<String key="position">407</String>
<String key="progafter">0</String>
<String key="progbefore">0</String>
<String key="programid">EP012968460038</String>
<String key="remainingtime">37:00</String>
<String key="starttime">2011-11-14T17:59:00</String>
<String key="state">WatchingPreRecorded</String>
<String key="subtitle">Free Rick</String>
<String key="title">American Chopper: Senior vs. Junior</String>
<String key="titleidx">1</String>
<String key="totaltime">1:02:25</String>
</State>
</FrontendStatus>

How can I get just the "WatchingPreRecorded" from the state key?

Thanks for the help

Try OpenRemote 2.0 How To - Use XML Data Sources

Posted by pz1 at Oct 17, 2013 12:10

I have looked at that page but all the examples has different names for each element where as the in the response I receive they all named <String key= so am not sure how I can pick a specific value out of the list.

Thanks

Posted by jasonc at Oct 18, 2013 10:31

You should google on XPath and see how that works.

For instance, you have this site: http://www.w3schools.com/xpath/
Then you can use a site such as http://www.xpathtester.com to test your expressions before using in OR.

For your specific case, use

//String[@key='state']/text()
as the XPath and you'll get what you want.

Posted by ebariaux at Oct 18, 2013 13:09

All have element name string, with attribute key.
The tutorial page I referred to does explicitly deal with this element/attribute issue. According to that page the XPATH for getting the state should be something like:

//FrontendStatus/String/@state

(I haven't tested this)

Posted by pz1 at Oct 18, 2013 14:55

Hi Thanks for the help, I eventaully worked out the problem I was having was that what was being returned
was not what was stated on the site above. Instead this is what was being returned:

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

<FrontendStatus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" serializerVersion="1.1">
<State>
<String>
<Key>currentlocation</Key>
<Value>library.xml</Value>
</String>
<String>
<Key>menutheme</Key>
<Value>defaultmenu</Value>
</String>
<String>
<Key>state</Key>
<Value>idle</Value>
</String>
</State>
<ChapterTimes/>
<SubtitleTracks/>
<AudioTracks/>
</FrontendStatus>

And the XPATH required was //StringKey='state'/Value/text()

Thanks again for the help

Posted by jasonc at Oct 19, 2013 04:34

Was to quick in trying to match your question with the examples on the page I produced

I'll extend the page I referred to with something like your example, because that situation of multiple use of the same attribute is not yet covered.

Posted by pz1 at Oct 19, 2013 09:13

Thanks that will make it easier for others in the future.

I'll try and write a tutorial on controlling MythTV via HTTP once I work everything out.

Posted by jasonc at Oct 21, 2013 05:46

I tested your expression in my XML development suite. Apparantly the WIKI formatter spoiled your expression. It should be:

//FrontendStatus/State/String[Key='state']/Value/text()

(I prefer to use the full path from the top-element in my XPATH expressions, that's why I included FrontendStatus/State)

PS1: For better readability enclose your code within {code}..{code} tags (see markup instructions). Do not place a / inside the end tag.
Formatting makes the code easier to read, which increases your chances to get an answer

PS2: MYTH apparantly changed their XML abandoning the attributes. I guess that is done to make it easier to maintain both a JSON and an XML interface.

Posted by pz1 at Oct 21, 2013 09:53
Document generated by Confluence on Jun 05, 2016 09:40