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?
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?
Never mind. I changed it to “rsp.foo[0]@att.tostr ()” and it’s working
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?
“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
EnTerr
November 25, 2014, 6:27pm
7
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
Native is always better and it’s faster not using plugins. But thanks for the information anyways.