Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
I'm trying to write a little program, that changes a value in an xml file. I want to edit the text between two tags.
<option>text to change</option>

Could you please help?
Posted
Comments
Maciej Los 16-Dec-14 17:11pm    
VB or VB.NET?

1 solution

Start here: XML in Visual Basic[^] and follow the links on the left.

There is at least few ways:
How to read XML from a file by using Visual Basic .NET [^]
HOW TO: Serialize and Deserialize XML in Visual Basic .NET[^]
How to: Parse XML with XmlReader[^]
Overview of LINQ to XML in Visual Basic[^]

Sample code: How To Modify and Save XML with the XmlDocument Class in the .NET Framework SDK[^]

Let's say your xml looks like:
XML
<options>
  <option>initial text</option>
</options>


The code could looks like:
VB
Dim xdoc As XDocument = XDocument.Load("D:\opt.xml")

Dim ele = xdoc.Elements("options").Elements("option")
ele.Value = "optional text"
xdoc.Save("D:\opt.xml")


Result:
XML
<options>
  <option>optional text</option>
</options>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900