Reading in XML

I am having an issue reading in XML. If I have a file such as a config file with multiple nodes of the same name, how do I read them in <configuration>
<appSettings>
<add key="myProfession" value="Computer Programmer" />
<add key="myName" value="Jason" />
</appSettings>
</configuration>Does anyone have any ideas


Answer this question

Reading in XML

  • vidya_084

    I figured out how to read it in, but I'm still having an issue. Here is my example of how to read and update the myName key:        Dim myConfig As New XmlDocument()
            Dim xmlConfig As XmlAttributeCollection
            Dim xmlUser As XmlAttribute
            myConfig.Load("myapp.exe.config")

            xmlUser = myConfig.SelectSingleNode("configuration/appSettings/add[@key='myName']/@value")
            xmlUser.Value = cfgUser.Text

            myConfig.Save("myapp.exe.config")

            Me.Close()Now my issue is that I need the config to be <b>refreshed</b> without closing out of the app and getting back in. Does anyone know how to do this

  • Sans103171

    I did know that. I was trying to take advantage of the one they provide. The System.Configuration namespace is read only so I can't really write to it that way. I also have a strange quarky issue when I try to update more than one key. It appears it works fine in the application. However the actual config never gets changed. Isn't that weird
  • jweisz

    I load in the config by using the System.Configuration namespace. Doing it that way, it still has the old config loaded. Is there a way to refresh it
  • Imran007

    yes, very weird...want to paste your code
  • Werner Swiegers

    i don't understand your new question about refreshing.  When you call the .Save method, your changes are saved to disc.  So what do you mean by Refresh
  • jordan kaliher

    I figured out the actual issue. It's here: <post>1110</post>
  • sdewan

    dang, that really sux...I never noticed that.  Only way I can see is to write your own configuration section reader/writer.

    there's actually an example of this in the ASP.NET Forums Source Code

  • Reading in XML