Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm a zero (or almost) in development but I'm trying to do simple application using XML file for some settings. I have a probably simple question but all the information I found an the web didn't helped me to find a working solution.

I'm working with VisualStudio2013 in VB.net and I'm trying to update values in the xml file strucutred like this :
XML
<config>
  <path>
    <path1>c:\test</path1>
    <path2>c:\windows</path2>
    <path3>c:\users</path3>
    <path4>c:\temp</path4>
  </path>
  <option>
    <option1>something</option1>
    <option2>anything</option2>
  </option>
</config>


As you can imagine, I'm trying to modify some path and option value.

If you have a solution for me it would be awsome...

Thank you,
Vince.
Posted
Comments
[no name] 22-Jul-14 14:49pm    
A solution to....?
MBV-Media 22-Jul-14 14:57pm    
Sorry, I thought I was clear enough but re-reading my message I understand I was not ;)

I would like help to update the right part of that XML file and save it with the new value I want to set. The value will come from a text box.

Thank you
[no name] 22-Jul-14 15:02pm    
Okay... that's a bit clearer. What have you tried? What is the problem with what you have tried? What is it that someone could do to help you?

1 solution

The simplest way is to use DataSet[^], which provide a way to read[^] and write[^] XML.
In this case, you need to add two DataTables[^] to the DataSet, one for path node and one for option node. Each DataTable should contains columns which correspond to node structure (respectively: path1 to path4 and option1 to option2).

There is several other ways to to that (i.e.: XmlDocument[^]), but i suggest to move your attention on XML serialization and deserialization[^], which can help you to convert an object into an XML form and vice versa. Use SearchBox[^] on the right-top corner of this site to search for articles about XML serialization and deserialization.
 
Share this answer
 
Comments
CPallini 22-Jul-14 15:17pm    
5.
Maciej Los 22-Jul-14 15:18pm    
Thank you, Carlo ;)
MBV-Media 23-Jul-14 5:01am    
Hi guys,

Thank you for the information. This is still a litlle bit like chineese for me but I have more details to search on Google how to do it ;)

I've tried before several ready made codes found on the web but never been able to make it work as I still have trouble understanding the different levels inside xml files... Elements, nodes, nodechild, ... are not that easy to understand for novice ;)

Thank you again... Now back to Google to make it work ;o)))

Vince.
Maciej Los 23-Jul-14 5:26am    
You're welcome ;)

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