jvalero
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2012
12:15 PM
Parsing Child Node Attributes in XML
I have a section in my XML that looks like the following:
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.
<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.
2 REPLIES 2

TheEndless
Channel Surfer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-03-2012
01:15 PM
Re: Parsing Child Node Attributes in XML
This code will print the value of the "value" attribute of each "param" node:
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.
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)
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
jvalero
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2012
10:08 AM
Re: Parsing Child Node Attributes in XML
Okay I got your example working. Appreciate the help. 😄