Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How to update the value in XML tag using C#. i have attached my code below i want change <name>Laptops this value to like <name>Books .Plz help me

thank you.
XML

<stockgroup name="Laptops" action="Create">
<name.list>
<name>Laptops</name> 
</name.list>
<parent /> 
<isaddable>Yes</isaddable> 
</stockgroup>
Posted
Updated 24-Sep-12 21:09pm
v4
Comments
Kenneth Haugland 25-Sep-12 3:07am    
XElement would work nicely here i think.
kiransnsns 25-Sep-12 3:24am    
Can you explain briefly.

thank you

Example:
XML
<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":
C#
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);
 
Share this answer
 
Hi,

Here is the link for you for all XML related operations with examples.

Here[^]

Thanks
--RA
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900