Reputation: 170
I am very inexperienced in both using Brightscript and working with XML content, but I am currently challenged with doing both to develop a roku app. At the moment, I need to figure out how to sort through some XML from an online document to get some necessary data. Any advice would be appreciated.
here's what the XML document looks like. (more items exist within MediaModel nodes, but I do not think I need them.)
<ArrayOfMediaModel xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/BlueBridgeIntegration.Models">
<MediaModel>
<Archive_ID>...</Archive_ID>
<Archive_Title>...</Archive_Title>
<Description>...</Description>
<Image_Path>...</Image_Path>
<MP3>...</MP3>
<MP4>...</MP4>
<RTMP_Path>...</RTMP_Path>
<Series_ID>...</Series_ID>
<Title>...</Title>
</MediaModel>
<MediaModel>...</MediaModel>
<MediaModel>...</MediaModel>
...
<MediaModel>...</MediaModel>
</ArrayOfMediaModel>
Although summarized, this is the extent of the document. The most important items of information I need to extract from the XML is title, description, image, and the mp4.
In its current state, the code I have does little more than parse the XML content, but this is what code I have so far.
sub CreateRecentMenu()
screen = CreateObject("roGridScreen")
port = CreateObject("roMessagePort")
xml = CreateObject("roXMLElement")
xml_str = GetXML("[url to the XML document]")
xml.Parse(xml_str)
...
return
end sub
Thus far, my attempts to obtain the information I need from the document has proven program-breaking. Again, any advice is very much appreciated. Thank you.
EDIT: I was able to determine that the xml_str string is coming up as invalid, for what reason I am not sure. This is the code I have for obtaining the XML code as a string.
Function GetXML(url as String) as string
data = ""
port = CreateObject("roMessagePort")
link = CreateObject("roUrlTransfer")
link.setPort(port)
link.setUrl(url)
link.SetCertificatesFile ("common:/certs/ca-bundle.crt")
link.InitClientCertificates ()
if(link.AsyncGetToString())
finished = False
while not finished
msg = wait(0, port)
if msg = invalid
finished = True
print "failure to connect"
link.AsyncCancel()
else
if type(msg) = "roUrlEvent"
finished = True
if msg.GetInt() = 1
response = msg.GetResponseCode()
if response <> 200
print response
else
data = msg.GetString()
end if
end if
else
return invalid
end if
end if
end while
end if
return data
End Function
Thus far, this is the only way i've been able to make the connection work. Again, any help is appreciated.
Upvotes: 0
Views: 314
Reputation: 954
Make sure that xml_str variable is not empty or invalid and GetXML function works well.
Upvotes: 1