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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Parsing Child Node Attributes in XML

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

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
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
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: - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos

Re: Parsing Child Node Attributes in XML

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