I wrote a de-XML-izer for a case like yours, it "magically" converts roXml to a JSON-like structure. Don't know if it makes difference to you - but i'll share it here for posterity, perhaps it will help somebody:
function de_XML(xml):
attrs = xml.getAttributes()
res = [attrs]
chlds = xml.getChildElements(): if chlds = invalid then chlds = [ ]
for each child in chlds:
dex = de_XML(child)
if type(dex) = "String":
attrs[child.getName()] = dex
else:
res.push(dex)
end if
end for
if res.count() < 2 then res = attrs
if res.isEmpty() then res = xml.getText()
return res
end function
Feed it a roXmlElement after a .parse() and it returns array (ordered list) 1..N of elements, with leaf nodes folded together with attributes in [0]-th element.
Testing it on your feed:
BrightScript Debugger> xfer = createObject("roUrlTransfer")
BrightScript Debugger> xfer.setURL("http://services.tvrage.com/feeds/fullschedule.php?country=US")
BrightScript Debugger> s = xfer.getToString(): ? len(s)
947987
BrightScript Debugger> x = createObject("roXmlElement")
BrightScript Debugger> x.parse(s)
BrightScript Debugger> xx = de_XML(x)
BrightScript Debugger> ss = formatJSON({_: xx}) : ? len(ss)
712524
BrightScript Debugger> ? left(ss, 1000)
{"_":[{},[{"attr":"2014-11-12"},[{"attr":"06:00 am"},{"ep":"17x285","link":"http://www.tvrage.com/Fox_and_Friends/episodes/1065649505","name":"Fox & Friends","network":"FOX NEWS channel","sid":"6978","title":"Season 17, Episode 285"},{"ep":"07x226","link":"http://www.tvrage.com/Mike_And_Mike_in_the_Morning/episodes/1065650083","name":"Mike & Mike","network":"ESPN 2","sid":"10566","title":"Season 7, Episode 226"},{"ep":"20x70","link":"http://www.tvrage.com/Squawk_Box/episodes/1065650146","name":"Squawk Box","network":"CNBC","sid":"18743","title":"Season 20, Episode 70"},{"ep":"10x28","link":"http://www.tvrage.com/Morning_Express_with_Robin_Meade/episodes/1065650204","name":"Morning Express with Robin Meade","network":"Headline News","sid":"19917","title":"Season 10, Episode 28"},{"ep":"08x08","link":"http://www.tvrage.com/ben-10-omniverse/episodes/1065703086","name":"Ben 10: Omniverse","network":"Cartoon Network","sid":"31489","title":"Most Dangerous Game Show"},{"ep":"02x156","link":"h
Dumping as json It's not too readable but if i pretty-print it, here is what's inside xx:
[
{ },
[
{ attr: "2014-11-10" },
[
{ attr: "06:00 am" },
{
ep: "17x283",
link: "http:\/\/www.tvrage.com\/Fox_and_Friends\/episodes\/1065649503",
name: "Fox & Friends",
network: "FOX NEWS channel",
sid: "6978",
title: "Season 17, Episode 283"
},
{
ep: "01x46",
link: "http:\/\/www.tvrage.com\/bloomberg-surveillance\/episodes\/1065655054",
name: "Bloomberg Surveillance",
network: "Bloomberg TELEVISION",
sid: "44969",
title: "Season 1, Episode 46"
},
'...
],
[
{ attr: "07:00 am" },
'...
],
' ...
],
[
{ attr: "2014-11-11" },
[
{ attr: "06:00 am" },
'...
]
' ...
]
]
from what originally was
<?xml version="1.0" encoding="UTF-8" ?>
<schedule>
<DAY attr="2014-11-10">
<time attr="06:00 am">
<show name="Fox & Friends">
<sid>6978</sid>
<network>FOX NEWS channel</network>
<title>Season 17, Episode 283</title>
<ep>17x283</ep>
<link>http://www.tvrage.com/Fox_and_Friends/episodes/1065649503</link>
</show>
<show name="Bloomberg Surveillance">
<sid>44969</sid>
<network>Bloomberg TELEVISION</network>
<title>Season 1, Episode 46</title>
<ep>01x46</ep>
<link>http://www.tvrage.com/bloomberg-surveillance/episodes/1065655054</link>
</show>
' ...
</time>
<time attr="07:00 am">
' ...
</time>
'...
</DAY>
<DAY attr="2014-11-11">
<time attr="06:00 am">
'...
</DAY>
'...
<schedule>
And here is example of using the result:
function dump(schedule):
for i = 1 to 2 'schedule.count()-1:
day_sched = schedule[i]
day = day_sched[0].attr
for j = 1 to 2 'day_sched.count()-1:
hour_sched = day_sched[j]
time = hour_sched[0].attr
for k = 1 to 2 'hour_sched.count()-1:
? day, time, hour_sched[k].name
end for
end for
end for
end function
BrightScript Debugger> dump(xx)
2014-11-10 06:00 am Fox & Friends
2014-11-10 06:00 am Mike & Mike
2014-11-10 07:00 am Good Morning America
2014-11-10 07:00 am Today (US)
2014-11-11 06:00 am Fox & Friends
2014-11-11 06:00 am Mike & Mike
2014-11-11 07:00 am Good Morning America
2014-11-11 07:00 am Today (US)
(Here for brevity i printed just the first 2 shows from the first 2 hours from the first 2 days)
PS. (11/13) fixed
de_XML to not depend on
roAA.count() existence (replaced
res.count() < 1 with
res.isEmpty() - which works for both roArray and roAA). Also updated example to avoid
formatJSON(roArray). Both features are not in current fw5.6