XML Mass Changing Type Hexadecimal

Multi tool use
Multi tool use


XML Mass Changing Type Hexadecimal



So I have 80 000 lines of XML. They follow this general structure:


<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>





But what I want to do is change all the types of the XML.



The type is this part:


type="0xa14"



I want them to start from the beginning (first XML) with 0x00 then increase by 1 in hexadecimal until it reaches the end.



Here is the pure pastebin of the XML file:
XML Github File





"0xa14" has 3 hex characters, "0x00" has 2, please explain
– TheGeneral
Jun 30 at 5:19




2 Answers
2



Simple using xml linq :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:temptest.xml";
static void Main(string args)
{
XDocument doc = XDocument.Load(FILENAME);

int index = 0;
foreach(XElement obj in doc.Descendants("Object"))
{
obj.SetAttributeValue("type", "0x" + index++.ToString("x"));
}
}
}
}



You can use XDocument and update all type attributes in the loop


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");






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

E6gbKCGDyv xtuSLXZWHOKpLDz5B2L YG3 0Xb6CST lgFJyszuJS4UBFTwbfluQYAtb86Ov0H72luFnKojQupEd6L6OX,pzVFEG
tADLD6deN8rMs2QDi39ZHjrHVF16,n,ufUgIMjwF9hPMpnSr3 k185U7ab02yGmLO3kiRJiLpSMr DsGTdqYEe,fiE ObLfb

Popular posts from this blog

Delphi Android file open failure with API 26

.

Amasya