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: 

XML Parsing Structure

So the documentation for the roXMLElement object and parsing is fairly quiet and minimal on this issue.

http://sdkdocs.roku.com/display/sdkdoc/roXMLElement

Given an example XML file


<?xml .... ?>
<feed>
<foo att="something">
<bar>text</bar>
<test>text</test>
</foo>
<foo att="something2">
<bar>text2</bar>
<test>text2</test>
</foo>
</feed>


What does the structure look like when parsed through the roXMLElement command?


rsp = CreateObject("roXMLElement")
rsp.Parse(html)


I know you can call it like "rsp.foo[1]" and "rsp.foo[1].bar, but how do you extend that to attributes?
שלום חבר

Dean at the School of Truth: a part of Autodidact University.

"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum
0 Kudos
7 REPLIES 7
TheEndless
Channel Surfer

Re: XML Parsing Structure

"DukeOfMarshall" wrote:
I know you can call it like "rsp.foo[1]" and "rsp.foo[1].bar, but how do you extend that to attributes?

Attributes are accessed either via the @ shortcut or the GetAttributes() method. So, given you example above, you can get to "att" on the first "foo" element with "rsp.foo[0]@att".
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

Re: XML Parsing Structure

Thanks for the help. I'm calling it like this "rsp.foo[0]@att.gettext()", but the debugger reports


Member function not found in BrightScript Component or interface


Do I have something else incorrect here?
שלום חבר

Dean at the School of Truth: a part of Autodidact University.

"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum
0 Kudos

Re: XML Parsing Structure

Never mind. I changed it to "rsp.foo[0]@att.tostr()" and it's working
שלום חבר

Dean at the School of Truth: a part of Autodidact University.

"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum
0 Kudos

Re: XML Parsing Structure

So here's a follow up. Why does this not work when simply printing to the debugger


print "Image => "+rsp.foo[0]@att.gettext()


But this DOES work when printing to debugger


print "Image => "+rsp.foo[0]@att.tostr()


But neither work when setting the attribute


o.SDPosterUrl = rsp.foo[0]@att.gettext()
o.HDPosterUrl = rsp.foo[0]@att.tostr()


Instead I have to do this


hd_image = rsp.foo[0]@att
o.HDPosterUrl = hd_image


What in the world?
שלום חבר

Dean at the School of Truth: a part of Autodidact University.

"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum
0 Kudos
TheEndless
Channel Surfer

Re: XML Parsing Structure

"DukeOfMarshall" wrote:
So here's a follow up. Why does this not work when simply printing to the debugger


print "Image => "+rsp.foo[0]@att.gettext()


But this DOES work when printing to debugger


print "Image => "+rsp.foo[0]@att.tostr()


But neither work when setting the attribute


o.SDPosterUrl = rsp.foo[0]@att.gettext()
o.HDPosterUrl = rsp.foo[0]@att.tostr()


Instead I have to do this


hd_image = rsp.foo[0]@att
o.HDPosterUrl = hd_image


What in the world?

The @ shortcut returns a string, not an roXmlElement. Calling .toStr() is redundant in this case. This should work just fine:
o.SDPosterUrl = rsp.foo[0]@att
o.HDPosterUrl = rsp.foo[0]@att
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
EnTerr
Roku Guru

Re: XML Parsing Structure

If you prefer working with nested arrays and dictionaries instead, you can try this converter viewtopic.php?f=34&t=75809#p462597 - on your example it will return
[ 
{ },
{ att: "something", bar: "text", test: "text" },
{ att: "something2", bar: "text2", test: "text2" }
]
and then can access as
o.HDPosterUrl = rsp[1].att
0 Kudos

Re: XML Parsing Structure

Native is always better and it's faster not using plugins. But thanks for the information anyways.
שלום חבר

Dean at the School of Truth: a part of Autodidact University.

"A programmer is just a tool which converts caffeine into code"
Temet nosce
Vi Veri Veniversum Vivus Vici
Si vis pacem, para bellum
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.