Search code examples
xmlrokubrightscript

Unable to parse xml string in Brightscript


I am currently trying to create an application for Roku where the user can find and watch some of the most recent recorded church services available from my church's archives. To do this, I access an API containing an XML document with data pertaining to said recordings. The document contains an element called ArrayOfMediaModel which has at least 30 or more elements within it which are called MediaModel nodes. My hope is to parse the information from these nodes in order to create and play video feed for the end user

That being said, I can't seem to parse the information. Every time I try, I get the following error in the command prompt:

Function call operator () attempted on non-function. (runtime error &he0) in pkg:/source/CreateRecentMenu.brs(8)

Here is the code I have for this operation. As you can assume by the title, it is written in Brightscript.

sub CreateRecentMenu()
   screen = CreateObject("roGridScreen")
   port = CreateObject("roMessagePort")
   xml = CreateObject("roXMLElement")
   screen.setMessagePort(port)

   xml = GetXML("[a url exists here which i removed in this post]")
   Parse (xml)

   'more code occurs beyond this, but the function crashes upon the Parse() call

end sub

The GetXML function retrieves data from the XML file specified by the url (which, again, I removed for the sake of posting here) and returns a string. I have tested the result of this and I am confident that it properly returns the string as is intended.

Reading over the documentation of Roku Brightscript, it seems like this should work but it does not. It is also my understanding that, in order to retrieve any meaningful information from the xml document, I have to perform the Parse() function to the xml string. Any help provided is greatly appreciated.


Solution

  • No wonder, you are confused what xml exactly is - is it the parsed object or the xml text. Try this:

       xml = CreateObject("roXMLElement")
       xml_str = GetXML("[a url exists here which i removed in this post]")
       xml.parse(xml_str)