tags:

views:

158

answers:

2

Hi,

With the following XML I am trying to copy and add to another XML but I haven't used the C# XML document objects before. So here is the XML

<config>
   <configXML>
      <Connections>
         <Connection excyptedConnection="encrypted string">
      </Connections>
   <configXML>
</config>

I want to be able to copy out the Connection or add new Connection information. I want to be able to use the /config/configXML/Connections/ xpath for adding/copying the values.

Anyone that can help?

Thanks

A: 
Traveling Tech Guy
I'd question this being simpler. Care to post a code sample comparable to Richard Hein's?
TrueWill
I could, but it would probably look very similar to Richard's code.
Traveling Tech Guy
+2  A: 

Try something like this:

var path = "c:\\temp\\myXml.xml";    
XDocument doc = XDocument.Load(path);
var element = doc.XPathSelectElement("config/configXML/Connections/Connection");
element.Attribute("encryptedConnection").Value = "Whatever";    
doc.Save(path);
Richard Hein