Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Struggling with XML Parsing

Hello,

I'm about to write a roku channel to connect a roku device with a enigma2 settop-box for live streaming events.

I figured out a bunch of different problems. For example, I can only use the transcoded streaming because the roku device can't handle live TV streaming, even when both streams have mpeg4 as video codec. But nevermind, that is not the issue that I'm currently facing.

To get the TV channels from my enigma2 settop-box, I need to retrieve and parse XML files on my roku device. But it is not working correctly.

The example XML file looks like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<e2servicelist>
	<e2service>
		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.deutschland__tv_.tv" ORDER BY bouquet</e2servicereference>
		<e2servicename>Deutschland</e2servicename>
	</e2service>
	<e2service>
		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.__sterreich__tv_.tv" ORDER BY bouquet</e2servicereference>
		<e2servicename>Österreich</e2servicename>
	</e2service>
	<e2service>
		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.mtv__tv_.tv" ORDER BY bouquet</e2servicereference>
		<e2servicename>MTV</e2servicename>
	</e2service>
	<e2service>
		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.sky__tv_.tv" ORDER BY bouquet</e2servicereference>
		<e2servicename>Fußball &amp; Sport</e2servicename>
	</e2service>
	<e2service>
		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.dbe00.tv" ORDER BY bouquet</e2servicereference>
		<e2servicename>Sky</e2servicename>
	</e2service>
	<e2service>
		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.favourites.tv" ORDER BY bouquet</e2servicereference>
		<e2servicename>Favourites (TV)</e2servicename>
	</e2service>
	<e2service>
		<e2servicereference>1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.LastScanned.tv" ORDER BY bouquet</e2servicereference>
		<e2servicename>Last Scanned</e2servicename>
	</e2service>
</e2servicelist>

 


That's the first entry point. Between each Bouquet, you'll find the tv channels, therefore another API call is required. But before I continue, I have to solve the issue that I'm currently facing.

I wrote this example code:

 

sub GetServices()
    services = {} ' roAssociativeArray / map
    responseXML = CreateObject("roXMLElement")
    serviceURL = CreateObject("roURLTransfer")
    serviceURL.SetURL("http://<user:password@device-ip>/web/getservices")
    rsp = serviceURL.GetToString()
    print rsp
    
    if not responseXML.Parse(rsp)
        print "Cannot parse the feed"
    endif
    
    print "The xml is of type "; type(responseXML)
    print "Name of xml is " ; responseXML.getName()
    print "Test 1a: " ; responseXML.e2service[0].getName()
    print "Test 1b: " ; responseXML.e2service[0].getText()
    print "Test 2a : " ; responseXML.e2service[1].getName()
    print "Test 2b : " ; responseXML.e2service[1].getText()
    print "Test 3a : " ; responseXML.e2service[0].e2servicereference[0].getName()
    print "Test 3b : " ; responseXML.e2service[0].e2servicereference[0].getText()
    print "Test 4a : " ; responseXML.e2service[0].e2servicename[0].getName()
    print "Test 4b : " ; responseXML.e2service[0].e2servicename[0].getText()

end sub

 

In line "print rsp" it is printing the whole xml file correctly, so I'm sure the whole file got transferred correctly. 

The output that I see when I'm connected with the debugging port is as follows:

Cannot parse the feed
The xml is of type roXMLElement
Name of xml is e2servicelist
Test 1a: e2service
Test 1b:

But after this line, the application stops. I'm expecting another output.

First of all: I don't understand why I'm getting the error "Cannot parse the feed" since it looks like that responseXML.Parse(rsp) is working.

However, I was not able to loop through the xml file with a for each loop, so I tried to print different variables to figure out what's going on.

I would expect the following output regarding to the Roku SDK Documentation:
Test 1a: e2service
Test 1b: 
Test 2a: e2service
Test 2b: 
Test 3a: e2servicereference
Test 3b: 1:7:1:0:0:0:0:0:0:0:FROM BOUQUET "userbouquet.deutschland__tv_.tv" ORDER BY bouquet
Test 4a: e2servicename
Test 4b: Deutschland

Even when I comment the lines for Test 2a and Test 2b out, I will get the output for 3a, but not for 3b. So it seems like that in that line, the XML parser has issues and therefore it won't reach the line with the e2servicename or the 2nd object.

Just to understand the documentation correctly, I should be able to use "for each e2service in xmlResponse.getChildNodes()"  instead of responseXML.e2service[<int>] ? This is not working at all, but I guess it's because the xml file does not get parsed correctly.

I also tried to replace the ":" character with "&colon;" and the substrings " "userbouquet" / " tv" " also. Because I was not sure if these characters where causing the errors, but I still wasn't successful.

Please assist 🙂 

Edit:

The following replacements seems to work 🙂

rsp = rsp.Replace(chr(34) + "userbouquet","&quot;userbouquet")
rsp = rsp.Replace("tv" + chr(34),"tv&quot;")
rsp = rsp.Replace("Ä","&Auml;")
rsp = rsp.Replace("Ö","&Auml;")
rsp = rsp.Replace("Ü","&Auml;")
rsp = rsp.Replace("ä","&Auml;")
rsp = rsp.Replace("ö","&Auml;")
rsp = rsp.Replace("ü","&Auml;")
rsp = rsp.Replace("ß","&szlig;")

1 REPLY 1
haytwozed
Newbie

Re: Struggling with XML Parsing

Hello,

Are you still working on this channel? I do hope so as it will be much appreciated in my household. I don't know if you intend to charge, but I for one would be happy to pay a reasonable annual subscription for access.

Thanks for all your efforts and good luck.

Ben

0 Kudos