Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Read/Write XML data in C# >Thread Next - Re: Read/Write XML data in C# Re: Read/Write XML data in C#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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
