Edit specific Element in XDocument

前端 未结 4 1573
萌比男神i
萌比男神i 2020-11-29 07:23

I recently started learning C# and I ran into a problem using XML.Linq to store data. I hope the question is understandable as I am not familiar with all the co

4条回答
  •  清酒与你
    2020-11-29 07:34

       UpdateGameAttr(id ,  bal);
    
       private void UpdateGameAttr(int id, int bal)
       {
           XDocument gmaes = XDocument.Load(@"D:\xxx\xxx\Game.xml");            
    
           XElement upd = (from games in games.Descendants("savegame")
                          where games.Element("IdNumber").Value == id.ToString()
                          select games).Single();
           upd.Element("balance").Value = bal.ToString();
           gmaes.Save(@"D:\xxxx\xxx\Game.xml");
    
       }
    

提交回复
热议问题