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

GetChildElements erroneously returns <UNINITIALIZED>

Hi,

My app downloads and parses some XML that contains


...
<categoryList>
<category>Name1</category>
<category>Name2</category>
<category>Name3</category>
</categoryList>


And successfully parses down to


if posterItem.Getname() = "categoryList" then
categoryItems = posterItem.GetChildElements()
for each categoryItem in categoryItems
' CRASH: categoryItem = <UNINITIALIZED>
print categoryItem.GetName()


The problem is that when I print categoryItems from the dubugger, I get 3 valid children whose names match the expected category names. But when I try to iterate over categoryItems using for each, it always prepends three <UNINITIALIZED> values before the valid values.


Brightscript Debugger> p categoryItems
<Component: roXMLElement>
<Component: roXMLElement>
<Component: roXMLElement>

Brightscript Debugger> p foreach categoryItem in categoryItems
<UNINITIALIZED><UNINITIALIZED><UNINITIALIZED><Component: roXMLElement>
<Component: roXMLElement>
<Component: roXMLElement>


Does anyone know why that may be, and how I could fix or workaround the problem or detect the error upstream? I don't see any problem with the XML itself.
0 Kudos
5 REPLIES 5
RokuMarkn
Visitor

Re: GetChildElements erroneously returns <UNINITIALIZED>

This seems to be a problem with the debugger but not with the language. The failure happens when you run the foreach statement in the debugger, but it seems to work ok when compiled into a channel. This works for me:

string ="<list><c>name1</c><c>name2</c><c>name3</c></list>"
xml = createobject("roXMLElement")
if not xml.Parse(string) then stop
categoryItems = xml.getChildElements()
for each categoryItem in categoryItems
print categoryItem.GetName()
end for


This prints

c
c
c


--Mark
0 Kudos
RokuMarkn
Visitor

Re: GetChildElements erroneously returns <UNINITIALIZED>

Hm, actually I can't reproduce the problem with the debugger either. Can you give a complete example of how to reproduce it?

--Mark
0 Kudos
jlfreund
Visitor

Re: GetChildElements erroneously returns <UNINITIALIZED>

Hi, thanks for the quick reply. I was going to send the sample offline, but was able to sanitize it enough to post here (for everyone's benefit).


Sub Main()
rsp = "<menutree><roPosterScreen><categoryList><category>1</category><category>2</category><category>3</category></categoryList></roPosterScreen></menutree>" xml=CreateObject("roXMLElement")
xml.Parse(rsp)

rokumenu = xml.GetChildElements()
for each element in rokumenu
if element.GetName() = "roPosterScreen" then
posterScreen = element.GetBody()
endif
next

for each posterItem in posterScreen
if posterItem.GetName() = "categoryList" then
categoryItems = posterItem.GetChildElements()
for each catgoryItem in categoryItems
print "categoryItem: " + categoryItem.GetName()
if categoryItem.GetName() = "category" then
print "Push " + categoryItem.GetBody()
endif
next
endif
next
End Sub
0 Kudos
RokuMarkn
Visitor

Re: GetChildElements erroneously returns <UNINITIALIZED>

Hm this is a strange one. Simply changing the names of two variables (categoryItems -> cs and categoryItem -> c) seems to fix the problem. I've filed a bug on this and we will investigate.

--Mark
0 Kudos
jlfreund
Visitor

Re: GetChildElements erroneously returns <UNINITIALIZED>

Thanks! That workaround works for me as well.
0 Kudos