
DukeOfMarshall
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014
10:19 AM
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
What does the structure look like when parsed through the roXMLElement command?
I know you can call it like "rsp.foo[1]" and "rsp.foo[1].bar, but how do you extend that to attributes?
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
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
7 REPLIES 7

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014
10:33 AM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)

DukeOfMarshall
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014
10:49 AM
Re: XML Parsing Structure
Thanks for the help. I'm calling it like this "rsp.foo[0]@att.gettext()", but the debugger reports
Do I have something else incorrect here?
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
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

DukeOfMarshall
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014
10:50 AM
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
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

DukeOfMarshall
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014
11:12 AM
Re: XML Parsing Structure
So here's a follow up. Why does this not work when simply printing to the debugger
But this DOES work when printing to debugger
But neither work when setting the attribute
Instead I have to do this
What in the world?
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
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

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014
12:07 PM
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2014
10:27 AM
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
[and then can access as
{ },
{ att: "something", bar: "text", test: "text" },
{ att: "something2", bar: "text2", test: "text2" }
]
o.HDPosterUrl = rsp[1].att

DukeOfMarshall
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2014
10:31 AM
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
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