How do I edit this XML node? BIG POINTS!!

Using vb.net how do I update this XML?  I want to change the key of "001" to "002" and the value of "foo1" to "foo2"?

SAMPLE XML:      
<configuration>
     <appSettings>
          <add key="001" value="foo1" />
     </appSettings>
</configuration>


        I AM ALREADY ADDING, and DELETING (But I do not know how to UPDATE/EDIT the above):

        Dim configFile As String = "c:\config.xml"
        Dim xmlDoc As XmlDocument = New XmlDocument ' create a new XmlDocument object
        xmlDoc.Load(configFile) ' load the configuration file

        Dim appSettingsElement As XmlNode = xmlDoc.SelectSingleNode("//configuration/appSettings") ' get a reference to the <appSettings> section
        Dim newElement As XmlElement = xmlDoc.CreateElement("add") ' create a new <add> element

        newElement.SetAttribute("key", Trim(newKey.ToString))  ' set its key attribute
        newElement.SetAttribute("value", Trim(newKeyVal.ToString)) ' set its value attribute
        appSettingsElement.AppendChild(newElement) ' append it to the <appSettings> section

        xmlDoc.Save(configFile)
        xmlDoc = Nothing

       'TO DELETE I AM DOING:          myNode1.RemoveChild(myNode2), etc, etc... (In another routine...)

THANKS!

(URGENT)


afsanchez001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nayernaguibCommented:
The following piece of code should do the job:

____________________________________________

        Dim doc As New XmlDocument
        Dim nodes As XmlNodeList
        Dim i As Integer
        doc.Load("c:\config.xml")
        nodes = doc.SelectNodes("//configuration/appSettings/add")
        For i = 0 To nodes.Count - 1
            If nodes(i).Attributes("key").Value = "001" And nodes(i).Attributes("value").Value = "foo1" Then
                nodes(i).Attributes("key").Value = "003"
                nodes(i).Attributes("value").Value = "foo3"
            End If
        Next
        doc.Save("c:\config.xml")

____________________________________________

_______________

  Nayer Naguib
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
afsanchez001Author Commented:
I have not had a chance to test it but will let you know ASAP!
0
nehayaCommented:
This is a confgiration file!
use UserScope setting file and you can change it throu the proxy class!
0
afsanchez001Author Commented:
nehaya, can you please show an example?  Thank you.
0
afsanchez001Author Commented:
nayernaguib, Thank you!  Excellent answer.  : )
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Multimedia Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.