Jump to content

XML write help


Recommended Posts

Hi guys

im currently writing a programme that helps me quickly edit item attributes in my server data files while allowing to quickly ammend there categories spawn rates ect

the server likes XML and silly me forgot its not as simple as HTML as writing it in a text file (in my defence its 5am and i been quickly trying to write this out since last night)

So i have to some how convert my code below, to write into a XML file

i have looked up the XML udf, and it make no sence i dont even know were to start as its not as simple as convert or write this line, can someone help?

P.s i know its sloppy coding, just really late in the day lol

P.s.s Just fixed some missing "" in the text output in my script, just incase you guys notice it in the below

Code :

Func Build()
    SplashTextOn("Loading","Building file Please Wait!",500,100)
    FileDelete ( @ScriptDir & "/types.xml")

    FileWrite ( @ScriptDir & "/types.xml", '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' )
    FileWrite ( @ScriptDir & "/types.xml", "    <types>")

    $aArray = IniReadSectionNames(@ScriptDir & "/Data.ini")
    If Not @error Then
        For $i = 1 To $aArray[0]
        FileWrite ( @ScriptDir & "/types.xml", '        <type name=' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Name","??") & '>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Nominal","") <> "" then FileWrite ( @ScriptDir & "/types.xml", '           <nominal>' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Nominal","")&'</nominal>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Lifetime","") <> "" then FileWrite ( @ScriptDir & "/types.xml", '          <Lifetime>' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Lifetime","")&'</Lifetime>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Restock", "") <> "" then FileWrite ( @ScriptDir & "/types.xml", '          <Restock>' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Restock","")&'</Restock>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"min", "") <> "" then FileWrite ( @ScriptDir & "/types.xml", '          <min>' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"min","")&'</min>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Quantmin", "") <> "" then FileWrite ( @ScriptDir & "/types.xml", '         <Quantmin>' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Quantmin","")&'</Quantmin>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Quantmax", "") <> "" then FileWrite ( @ScriptDir & "/types.xml", '         <Quantmax>' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Quantmax","")&'</Quantmax>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Cost", "") <> "" then FileWrite ( @ScriptDir & "/types.xml", '         <Cost>' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Cost","")&'</Cost>')
        FileWrite ( @ScriptDir & "/types.xml", '            <flags count_in_cargo="0" count_in_hoarder="" count_in_map="0" count_in_player="0" crafted="0" deloot="0"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Category", "") <> "" then FileWrite ( @ScriptDir & "/types.xml", '         <category name=' & IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Category","")&'/>')

        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Shelves", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '            <tag name="shelves"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Floor", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '          <tag name="floor"/>')

        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Mil", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '            <usage name="Military"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Police", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '         <usage name="Police"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Farm", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '           <usage name="Farm"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"School", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '         <usage name="School"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Industrial", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '         <usage name="Industrial"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Hunting", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '            <usage name="Hunting"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Village", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '            <usage name="Village"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Prison", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '         <usage name="Prison"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Firefighter", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '            <usage name="Firefighter"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Office", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '         <usage name="Office"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Medic", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '          <usage name="Medic"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Town", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '           <usage name="Town"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Coast", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '          <usage name="Coast"/>')


        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Tier1", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '          <value name="Tier1"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Tier2", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '          <value name="Tier2"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Tier3", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '          <value name="Tier3"/>')
        if IniRead(@ScriptDir & "/Data.ini",$aArray[$i],"Tier4", "") = 1 then FileWrite ( @ScriptDir & "/types.xml", '          <value name="Tier4"/>')

        FileWrite ( @ScriptDir & "/types.xml", "        </type>")
        Next

EndIf
FileWrite ( @ScriptDir & "/types.xml", "    </types>")
    EndFunc

XML example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <types>
        <type name=ACOGOptic>
            <nominal>60</nominal>
            <Lifetime>7200</Lifetime>
            <Restock>1800</Restock>
            <min>16</min>
            <Quantmin>-1</Quantmin>
            <Quantmax>-1</Quantmax>
            <Cost>100</Cost>
            <flags count_in_cargo="0" count_in_hoarder="" count_in_map="0" count_in_player="0" crafted="0" deloot="0"/>
            <category name=weapons/>
        </type>
        <type name=AgaricusMushroom>
            <Lifetime>900</Lifetime>
            <flags count_in_cargo="0" count_in_hoarder="" count_in_map="0" count_in_player="0" crafted="0" deloot="0"/>
        </type>
        <type name=AK101>
            <nominal>20</nominal>
            <Lifetime>10800</Lifetime>
            <Restock>1800</Restock>
            <min>4</min>
            <Quantmin>-1</Quantmin>
            <Quantmax>-1</Quantmax>
            <Cost>100</Cost>
            <flags count_in_cargo="0" count_in_hoarder="" count_in_map="0" count_in_player="0" crafted="0" deloot="0"/>
            <category name=weapons/>
            <value name="Tier2"/>
            <value name="Tier3"/>
        </type>

Ini Example

["ACOGOptic"]
Name="ACOGOptic"
Category="weapons"
Nominal=60
Lifetime=7200
Restock=1800
min=16
quantmin=-1
quantmax=-1
cost=100
Military=1
["AgaricusMushroom"]
Name="AgaricusMushroom"
Lifetime=900
["AK101"]
Name="AK101"
Category="weapons"
Nominal=20
Lifetime=10800
Restock=1800
min=4
quantmin=-1
quantmax=-1
cost=100
Tier2=1
Tier3=1
Military=1

cheers in advance

 

:)

Edited by Thornhunt
missed a bit

Budweiser + room = warm beerwarm beer + fridge = too long!warm beer + CO2 fire extinguisher = Perfect![quote]Protect the easly offended ... BAN EVERYTHING[/quote]^^ hmm works for me :D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...