Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Read/Write XML data in C#

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 10/9/2008 6:42:00 PM

RLEE71 wrote:
> I'm using VS C# 2008 Express. I want to read data from an XML file and 
> display into a text box. I then want to be able to edit the data in the text 
> box and save back to the XML file. I've seen various examples of how to do 
> this, but I think that my particular XML file is more complicated. Any help 
> would be greatly appreciated. I'm concerned with the data in the IP_ADRESS, 
> SUBNET_MASK, GATEWAY_IP_ADRESS, and DNS_NAME tags under MOD_NETWORK_SETTINGS. 
> Also want to edit the ADD_USER PASSWORD data.

With VS 2008 you can and should use LINQ to XML to manipulate your XML:
http://msdn.microsoft.com/en-us/library/bb387098.aspx

Here is sample code that loads your XML sample, finds the 
MOD_NETWORK_SETTINGS element and changes the VALUE attribute of the 
DNS_NAME child element:

             XDocument doc = XDocument.Load(@"doc.xml");
             XElement mns = 
doc.Descendants("MOD_NETWORK_SETTINGS").FirstOrDefault();
             if (mns != null)
             {
                 XElement dname = mns.Element("DNS_NAME");
                 dname.SetAttributeValue("VALUE", "foo");
                 // make more changes here
                 // then save
                 doc.Save("doc.xml");
             }

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent