Hi, and thank you, FishingScout
I have now created the following code:
Dim configurationFile As New XmlDocument()
configurationFile.Load("C:\temp\webdir4\design2.xml")
Dim CountryCodeValueNodes As XmlNodeList
CountryCodeValueNodes =
configurationFile.SelectNodes("//type[@name='lstCountries']/values/value")
Dim CountryCodeValue As XmlNode
For Each CountryCodeValue In CountryCodeValueNodes
Dim CountryCode As String = CountryCodeValue.Attributes("key")
'do something with the country code ....
CheckedListBox1.Items.Add(CountryCode)
Next
However, when I try to run the code I receive the error: "Value of type
'System.Xml.XmlAttribute' cannot be converted to 'String'." referring to the
line "Dim CountryCode As String = CountryCodeValue.Attributes("key")"
What should I be doing to get rid of this?
Thanks for your help! One day I will give VB the time it deserves to
actually learn the fundamentals.
JB
[quoted text, click to view] "FishingScout" <fishingscout@comcast.net> wrote in message
news:1162064444.408677.229710@k70g2000cwa.googlegroups.com...
> John,
>
> First your xml is poorly formed. It is missing the closing </types>
> before the </design> tag.
>
> Next, to query the values node for the type whos name is "lstcountries"
> use the following:
>
> xmldocument.SelectSingleNode(
> "/design/types/type[@name='lstCountries']/values")
>
> or less specifically:
>
> xmldocument.SelectSingleNode("//type[@name='lstCountries']/values")
>
> That will return the the values node.
>
> However, it seems to me that you really want to get all the country
> codes. To do that you should get a node array of all the country code
> values. Use something like:
>
> Dim CountryCodeValueNodes As XmlNodeList =
> xmldocument.SelectNodes("//type[@name='lstCountries']/values/value")
>
> For Each CountryCodeValue as Node in CountryCodeValueNodes
> Dim CountryCode as String = CountryCodeValue.Attributes("key")
> ' do something with the country code ....
> Next
>