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: 
Bpelon
Visitor

Something that would be helpful for us new guys

So I'm new to the Roku SDK, been at it about a week. I'm pleased to be able to use the simple video player and have it up and running in a matter of hours on a streaming server running off of a live DB.

What I am trying to do at this point is actually become familiar with brightscript and the sdk. I feel like there is a pretty large gap from hello world on the blog, to most of the working examples provided with the SDK and in the language reference. I am more than happy to piece together my own application as 90% of the responses on the board seem to be, but it would be a lot easier for those of us not familiar with brightscript if the examples in the language reference could be stripped down more than they currently are.

For example, lets say I would like to learn how to load a remotely hosted xml file and parse it (a common starting point for most web applications). The language reference addresses that but I first need to strip a lot of unnecessary functionality from the flikr example that doesn't apply and it's a bit more confusing than helpful to a user at my experience level.

Just a thought.
0 Kudos
2 REPLIES 2
RokuJoel
Binge Watcher

Re: Something that would be helpful for us new guys

Very good points. I'm sure we will address this in a blog posting in the near future, and perhaps improve the documentation in this area as well.

to try to help you immediately:

Download an XML file:

xfer=createobject("rourltransfer")
xfer.seturl("http://myserver.com/data.xml")
RawXMLData=xfer.gettostring()


In parsing the file, it is helpful to know what it looks like, and what you want to map the data to, for example, if you want to parse data that will wind up on a roPosterScreen (and most other components that have a SetContentList method), you would want to map images to the SDPosterURL and HDPosterURL, and the title and subtitle of the content to the ShortDescriptionLine1 and ShortDescriptionLine2 fields, so say you have some XML that looks like this:

<items>
<item>
<title>This is a test</title>
<subtitle>This is a subtitle of the test title</subtitle>
<hdThumbnail>http://server.com/hdimage.jpg</hdThumbnail>
<sdThumbnail>http://server.com/sdimage.jpg</sdThumbnail>
<itemdescription>This is a long description of this item it is so long it goes on and on</itemdescription>
</item>
<item>
<title>This is also a test</title>
<subtitle>This is also a subtitle of the test title</subtitle>
<hdThumbnail>http://server.com/hdimage2.jpg</hdThumbnail>
<sdThumbnail>http://server.com/sdimage2.jpg</sdThumbnail>
<itemdescription>This is another long description of this item it is so long it goes on and on</itemdescription>
</item>
</items>


So assuming you have downloaded this xml from the server and it is stored as a string in the RawXMLData variable, then you would want to parse it:


xml=createobject("roXMLElement")
list=createobject("roArray",1,true)
if xml.parse(RawXMLData) then
for each obj in xml.item
currentitem=createobject("roAssociativeArray")
currentitem.shortdescriptionLine1=obj.title.gettext()
currentitem.shortdescriptionLine2=obj.subtitle.gettext()
currentitem.hdposterurl=obj.hdThumbnail.gettext()
currentitem.sdposterurl=obj.sdThumbnail.gettext()
currentitem.title=currentitem.shortdescriptionLine1
list.push(currentitem)
end for
else
print "parse failed"
end if


Assuming there are no bugs in the code and the xml parses, you will now have a variable, "list" which you can display on the screen:

screen=createobject("roposterscreen")
screen.show()
screen.setcontentlist(list)
while true
'prevent the program from exiting to the home screen
end while


If your xml has underscores or dashes in it, you would use currentitem=getNamedElements("tag_name").gettext()

*edit*:

further, if your xml has an element like:

<item publishdate="04/22/1999" duration="3600">


you would probably access that data as:

currentitem.pubdate=obj@publishdate
currentitem.duration=obj@duration

- Joel
0 Kudos
Bpelon
Visitor

Re: Something that would be helpful for us new guys

Thanks Joel,

That was extremely helpful and very easy to follow.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.