• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

load xml change and save

how can i load an xml file, change some of its values and save it in vb.net 1.1. The xml has to be something like this:

How do i loop through each childnode and change the age?

<parentNode>
<childNodes>
  <childNode>
      <age>10</age>
  </childNode>
  <childNode>
      <age>11</age>
  </childNode>
  <childNode>
      <age>12</age>
  </childNode>
<childNodes>
</parentNode>
0
vinny45
Asked:
vinny45
  • 2
1 Solution
 
broadbentCommented:
Frankly - parse it as a text file - it is much quicker than XML
0
 
Carl TawnSystems and Integration DeveloperCommented:
Something like the following should do the trick:

        Dim doc As New XmlDocument()
        doc.Load("C:\Test.xml")

        Dim nodes As XmlNodeList = doc.SelectNodes("//age")
        For Each node As XmlNode In nodes
            node.InnerText = "50"
        Next

        doc.Save("C:\Test.xml")
0
 
vinny45Author Commented:
carl tawn - will this lock the file while i navigate. Multiple users will be grabbing this file and saving it in another name
0
 
Carl TawnSystems and Integration DeveloperCommented:
It shouldn't do. You're not holding open the file, you simply load its contents into memory, so the file should be free for other people to read.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now