Click here to Skip to main content
15,908,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
i have an xml file like that
HTML
<employee Id="5" EmpName="emp" Email="x@y.c" DeptId="3" ChatStatus="0" />

I need to update ChatStatus attribute to be "1" according to employeeId.
Can Any One help me please?

Thanks
Posted
Updated 18-Jan-12 23:37pm
v2

Try this
XmlDocument doc = new XmlDocument();
doc.Load("filename.xml");
XmlNodeList nodelist = doc.SelectNodes("employee");
if (nodelist[0].Attributes["Id"].Value == "5")
  {
     nodelist[0].Attributes["ChatStatus"].Value = "1";
     doc.Save("filename.xml");
  }


This will update the first node,if you want you can loop through the nodes.
 
Share this answer
 
 
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