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: 
jvalero
Visitor

Parsing Child Node Attributes in XML

I have a section in my XML that looks like the following:
<adhocparams>
<param name="appname" value="headlines2"/>
<param name="sourceSite1" value="somesite.com"/>
<param name="sourceSite2" value="somesite.com"/>
<param name="sourceSite3" value="somesite.com"/>
<param name="sourceSite4" value="somesite.com"/>
<param name="ip" value="192.123.123.123"/>
</adhocparams>

What is the best way to parse out the value from a child node, for this example let's say the first param node.

I've tried many combinations to try and parse this value. With no luck. I was going to try using the GetAttributes method, but the documentation isn't complete for it and on my first few attempts it does not appear to work like JavaScript's getAttributes() which was what I was expecting.

Appreciate the help.
0 Kudos
2 REPLIES 2
TheEndless
Channel Surfer

Re: Parsing Child Node Attributes in XML

This code will print the value of the "value" attribute of each "param" node:

xmlString = "<adhocparams>....</adhocparams>"
xml = CreateObject("roXmlElement")
If xml.Parse(xmlString) Then
For Each paramNode In xml.param
print paramNode@value
Next
End If

The GetAttributes() method returns an associative array whose keys are the names of the attributes, so the GetAttributes() for the paramNode in your example would contain two keys: "name" and "value"
You can access attributes either using the "@" shortcut notation in the above code (if there are no special characters in the attribute name), or via the GetAttributes() associative array.
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
jvalero
Visitor

Re: Parsing Child Node Attributes in XML

Okay I got your example working. Appreciate the help. 😄
0 Kudos