?
Solved

Append to xml file

Posted on 2012-04-12
3
Medium Priority
?
318 Views
Last Modified: 2012-04-12
Is there a way to read an XML file and then "append" a line to it with vb code?

Example...on a button click event, could I add this
<add key="strCon" value="user id=lrbrister;pwd=mypassword;data source=lrbrister_dell\;initial catalog=mydatabaser"/>


To this mysettings.config file
<appSettings>
  <add key="KeyToOverride" value="Overridden" />
  <add key="KeyToBeAdded" value="EntirelyNew" />
</appSettings>

So that the file would now look like this
<appSettings>
  <add key="KeyToOverride" value="Overridden" />
  <add key="KeyToBeAdded" value="EntirelyNew" />
  <add key="strCon" value="user id=lrbrister;pwd=mypassword;data source=lrbrister_dell\;initial catalog=mydatabaser"/>
</appSettings>
0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 37837644
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 2000 total points
ID: 37838451
Try
Dim XReader = XElement.Load(New System.IO.StreamReader("YourXMLFile"))
XReader.Element("appSettings").Add(<add key="strCon" value="user id=lrbrister;pwd=mypassword;data source=lrbrister_dell\;initial catalog=mydatabaser"/>)
XReader.Save("YourXMLFile")

Open in new window

0
 

Author Closing Comment

by:lrbrister
ID: 37838658
Bewst "clean" answer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question