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: 
jbrave
Channel Surfer

Re: XML validity testing again

here's one idea for starters:

function validate(xmltag as string, obj as object) as boolean
xmlcheck=obj.getnamedelements(xmltag)
return xmlcheck<>invalid and xmlcheck.count() >0
end function
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
TheEndless
Channel Surfer

Re: XML validity testing again

What about a generic GetChildElementText() function?

Function GetChildElementText( parentElement As Object, childName As String, defaultValue = "" As String ) As String
child = parentElement.GetNamedElements( childName )
If child <> invalid and child.Count() > 0 Then
Return child.GetText()
Else
Return defaultValue
End If
End Function

Then your code can be simplified to:

m.TrackURL = GetChildElementText( track, "stream-url" )
m.TrackGenre = GetChildElementText( track, "genre" )
m.TrackDescription = GetChildElementText( track, "description" )
m.TrackCreated = GetChildElementText( track, "created-at" )
m.WaveformURL = GetChildElementText( track, "waveform-url" )
m.ArtworkURL = GetChildElementText( track, "artwork-url" )
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
jbrave
Channel Surfer

Re: XML validity testing again

Ok. What about a generic function that will do this for an unknown set of tags? So if I have m.xmltracklist, I could do something like:

taglist=extractTagList(m.xmltracklist)
for each tag in taglist
getChildElement(taglist.tag)
next


Since m.xmltracklist is an RoXMLElement, which appears to contain a list of roXMLElements:

BrightScript Debugger> ?type(m.xmltracklist)
roXMLElement
BrightScript Debugger> ?m.xmltracklist.GetChildElements()
<ROT:roXMLElement>
<ROT:roXMLElement>
<ROT:roXMLElement>
<ROT:roXMLElement>

which I assume represent each tag and its content, is there a way that you know of to get a list of all the tags in any given set of XML?

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
TheEndless
Channel Surfer

Re: XML validity testing again

I think you just discovered it yourself 😉
If you do a recursive loop through the roXMLElement.GetChildElements(), you can walk the entire document. GetName() should return the name of the element.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
jbrave
Channel Surfer

Re: XML validity testing again

sort of:

v=track.GetChildElements()

BrightScript Debugger> ?v.GetName()
Member function not found in BrightScript Component or interface.

BrightScript Debugger> ?v[1].GetName()
created-at
BrightScript Debugger> ?v[2].GetName()
user-id

Don't quite know what I would do a "for each" on... I can imagine doing: a

For i=1 to (v.count() -1)
? v
next

Any suggestions?
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
TheEndless
Channel Surfer

Re: XML validity testing again

For Each node in xml.GetChildElements()
print node.GetName()
Next
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
jbrave
Channel Surfer

Re: XML validity testing again

So if I understand this correctly, "node" is just a placeholder for "item" or "element" of an array, it doesn't have any meaning with relationship to the actual names of the elements of the array?

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
TheEndless
Channel Surfer

Re: XML validity testing again

Correct. It's just a variable equal to the current child element in the loop.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
jbrave
Channel Surfer

Re: XML validity testing again

Ok, thanks for explaining that!

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
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.