jlfreund
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2013
06:57 PM
GetChildElements erroneously returns <UNINITIALIZED>
Hi,
My app downloads and parses some XML that contains
And successfully parses down to
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.
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.
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.
5 REPLIES 5

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2013
09:37 AM
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:
This prints
--Mark
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

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2013
10:04 AM
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
--Mark
jlfreund
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2013
12:44 AM
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

RokuMarkn
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2013
09:03 AM
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
--Mark
jlfreund
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2013
07:11 PM
Re: GetChildElements erroneously returns <UNINITIALIZED>
Thanks! That workaround works for me as well.