By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Write an XML node

P: n/a
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!
Nov 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Major Aardvark wrote:
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!
Nov 1 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.