MY XML FILE STRUCTURE
-
1
True
Star Wars Fi
To update your xml use element method method of the XElement :
XDocument xmlDoc = XDocument.Load(HttpContext.Current.Server.MapPath("data.xml"));
var items = (from item in xmlDoc.Descendants("item")
where item.Element("itemID").Value == itemID
select item).ToList();
foreach (var item in items)
{
item.Element("itemID").Value=NewValue;
bool.Parse(item.Element("isGadget").Value)=Newvalue;
item.Element("name").Value=Newvalue;
item.Element("text1").Value=Newvalue;
}
xmlDoc.Save(HttpContext.Current.Server.MapPath("data.xml"));
or
XDocument xmlDoc = XDocument.Load(HttpContext.Current.Server.MapPath("data.xml"));
foreach (var item in (from item in xmlDoc.Descendants("item")
where item.Element("itemID").Value == itemID
select item).ToList())
{
item.Element("itemID").Value=NewValue;
bool.Parse(item.Element("isGadget").Value)=Newvalue;
item.Element("name").Value=Newvalue;
item.Element("text1").Value=Newvalue;
}
xmlDoc.Save(HttpContext.Current.Server.MapPath("data.xml"));
you get information form dynamic and update those changes in button click event means, first you checks the Page load following code is present
if(!Page.IsPostBack) { .... }