Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# XML
Hello,
 
How to update the value in XML tag using C#. i have attached my code below i want change Laptops this value to like Books .Plz help me
 
thank you.

<stockgroup name="Laptops" action="Create">
<name.list>
<name>Laptops</name> 
</name.list>
<parent /> 
<isaddable>Yes</isaddable> 
</stockgroup>
 
Posted 24-Sep-12 22:02pm
Edited 24-Sep-12 22:09pm
v4
Comments
Kenneth Haugland at 25-Sep-12 3:07am
   
XElement would work nicely here i think.
kiransnsns at 25-Sep-12 3:24am
   
Can you explain briefly.
 
thank you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Example:
<xml>
  <stockgroup name="Laptops" action="Create">
    <name.list>
      <name>Old Value</name>
    </name.list>
    <parent />
    <isaddable>Yes</isaddable>
  </stockgroup>
</xml>
Let's replace "Old Value" with "New Value":
string xmlFile = "test.xml";
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load(xmlFile);
xmlDoc.SelectSingleNode("xml/stockgroup/name.list/name").InnerText = "New Value";
xmlDoc.Save(xmlFile);
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
 
Here is the link for you for all XML related operations with examples.
 
Here[^]
 
Thanks
--RA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.150129.1 | Last Updated 25 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100