Solved

Append to xml file

Posted on 2012-04-12
3
311 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
3 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 37837644
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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