Write an XML node

M

Major Aardvark

Hi

I have read in an single node and it's list of values into a CheckedListBox
so that I can select which values I actually want to have in the node.

The question I now have is how can I write just this one node and its values
back to the original XML file, replacing the data that is already there?

Thanks for any suggestions you have!
 
R

rowe_newsgroups

Here's a quick example that might get you started. For starters prepare
the following xml document using notepad (or whatever) and save it on
your desktop as test.XML

<BaseNode>
<TargetNode>ChangeMe</TargetNode>
<TargetNode>DontChangeMe</TargetNode>
</BaseNode>

Ok, then here's the code I wrote real quick to look for a specific node
and change it's value.

Imports System.Xml

Module Module1

Sub Main()
' Change the below to match the file's directory
Dim dir As String = "C:\Documents and
Settings\username\Desktop\test.XML"
Dim doc As New XmlDocument
doc.Load(dir)
Dim nodelist As XmlNodeList =
doc.GetElementsByTagName("TargetNode")
For Each node As XmlNode In nodelist
If node.InnerText = "ChangeMe" Then
node.InnerText = "OKIwill"
End If
Next
doc.Save(dir)
End Sub

End Module

Hope that helps!

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top