- 好友
- 1
- 在线时间
- 0 小时
- 最后登录
- 2025-4-29
见习骑士

- UID
- 3209025
- 第纳尔
- 1316
- 精华
- 0
- 互助
- 2
- 荣誉
- 0
- 贡献
- 0
- 魅力
- 20
- 注册时间
- 2020-11-30
 鲜花( 3)  鸡蛋( 0)
|

楼主 |
发表于 2022-3-13 01:36:32
|
显示全部楼层
using System;
using System.IO;
using System.Xml;
namespace XmlEditor
{
class Program
{
static void AddSkillById(XmlDocument doc,string id,int add)
{
string xpath = String.Format("//skill[@id='{0}']", id);
XmlNodeList list = doc.SelectNodes(xpath);
foreach (XmlNode node in list)
{
XmlElement ele = (XmlElement)node;
String val = ele.GetAttribute("value");
int i = Convert.ToInt32(val);
i += add;
ele.SetAttribute("value", i.ToString());
}
}
static void Main(string[] args)
{
string path = Directory.GetCurrentDirectory() + @"\\spnpccharacters.xml";
XmlDocument doc = new XmlDocument();
doc.Load(path);
AddSkillById(doc, "OneHanded", 200);
AddSkillById(doc, "TwoHanded", 200);
AddSkillById(doc, "Polearm", 200);
string path2 = Directory.GetCurrentDirectory() + @"\\spnpccharacters_new.xml";
doc.Save(path2);
}
}
}
|
|