c# - XML 批量更改类型十六进制
问题描述
所以我有 80 000 行 XML。它们遵循以下一般结构:
<Object type="0xa14" id="Steel Dagger">
<Class>Equipment</Class>
<Item/>
<Texture>
<File>lofiObj5</File>
<Index>0x60</Index>
</Texture>
<SlotType>2</SlotType>
<Tier>0</Tier>
<Description>{equip.A_sharp_dagger_made_of_steel.}</Description>
<RateOfFire>1</RateOfFire>
<Sound>weapon/blunt_dagger</Sound>
<Projectile>
<ObjectId>Blade</ObjectId>
<Speed>140</Speed>
<MinDamage>20</MinDamage>
<MaxDamage>60</MaxDamage>
<LifetimeMS>400</LifetimeMS>
</Projectile>
<BagType>1</BagType>
<OldSound>daggerSwing</OldSound>
<feedPower>5</feedPower>
<DisplayId>{equip.Steel_Dagger}</DisplayId>
但我想做的是改变 XML 的所有类型。
类型是这部分:
type="0xa14"
我希望它们从 0x00 开头(第一个 XML)开始,然后以十六进制增加 1 直到它到达结尾。
这是 XML 文件的纯 pastebin: XML Github File
解决方案
您可以使用 XDocument 并更新type
循环中的所有属性
var document = XDocument.Load(@"pathToFile");
var index = 1;
foreach (var ground in document.Descendants("Ground"))
{
ground.Attribute("type").Value = index.ToString("X");
// 'X' convert integer to hexadecimal representation
index++;
}
document.Save(@"pathToUpdatedFile");
推荐阅读
- php - Redirect() 在使用@csrf POST 提交后不起作用,继续重新加载页面
- flutter - 颤振检查是屏幕堆栈顶部的页面
- r - 计算按 ID 分组的多行的标准差
- docker - 是否可以不使用 ExeUtils::MakeMaker 安装文档?
- jquery - 在 thymleaf 中添加和删除具有多个元素的动态行并与列表绑定
- libreoffice-calc - 使用文本单元格的内容来引用工作表
- python - 测试不对称图像
- r - 具有两个因子的多列的百分比
- python - 如何从 Python 中的多个数据框列绘制时间序列线图
- java - 为什么windows桌面不广播UDP?