Log in to reply
 

How to use oiv package to replace xml text



  • Can anyone help please?

    I know how to create oiv packages and add text to xml files, but I'm really struggling to create an oiv package that will replace certain text within an xml file.
    Basically, I want to create a "patch" for a script, so that users don't lose their customised data...
    I can give more info and examples, if anyone can help me...
    Thanks in advance šŸ™šŸ˜



  • @CaptConfuzed
    I haven't got a clue but you want to look at how mod authors insert dlc lines into 'dlclist.xml' & conduct a few tests :thumbsup:

    Example (taken from the 'assembly.xml' in this mod):

      <content>
        <add source="rmodlp770/dlc.rpf">update\x64\dlcpacks\rmodlp770\dlc.rpf</add>
        <archive path="update\update.rpf" createIfNotExist="False" type="RPF7">
          <text path="common\data\dlclist.xml" createIfNotExist="False">
            <insert where="Before" line="*&lt;/Paths&gt;*" condition="Mask">&lt;Item&gt;dlcpacks:\rmodlp770\&lt;/Item&gt;</insert>
          </text>
        </archive>
      </content>
    

    Hope it helps. Sorry, I can't help further. Best of luck :thumbsup:

    EDIT:

    Ah, I get ya now. "replace" doh. Sorry, I usually read the question thoroughly before answering.

    Ok (bare in mind I haven't got a f**king clue what I'm doing)... :some time later: ... here you go:

      <content>
        <add source="rmodlp770/dlc.rpf">update\x64\dlcpacks\rmodlp770\dlc.rpf</add>
        <archive path="update\update.rpf" createIfNotExist="False" type="RPF7">
          <text path="common\data\dlclist.xml" createIfNotExist="False">
            <replace line="*&lt;/Paths&gt;*" condition="Mask">&lt;Item&gt;dlcpacks:\replacedline\&lt;/Item&gt;</replace>
          </text>
        </archive>
      </content>
    

    That will replace the:

    </Paths>
    

    line at the bottom of 'dlclist.xml' with this one:

    <Item>dlcpacks:\replacedline\</Item>
    

    I tested it out & can confirm it works :thumbsup: (you know what I mean :D , it works to illustrate a replace of data within a '.xml' file (I'm ignoring the fact that my limited understanding of gobbledygook means it breaks 'dlclist.xml' functionality lol).
    Given that what you want to replace should not have been edited by the user I think it may be fit for purpose (with a little editing of course) :thumbsup:.
    Try it out anyway, see if you can use it for what you want & let me know how you get on :thumbsup:



  • Oh wow! Am going to give it a try today. I need to replace a significant amount of text though, so really hope it works...

    Thanks so much for getting back to me - you're the only one that's replied on any of the 5 forums I've posted on, and including DM's to some 'of the best' modders (apparently!)



  • @a63nt-5m1th said in How to use oiv package to replace xml text:

    <archive path="update\update.rpf" createIfNotExist="False" type="RPF7">
    <text path="common\data\dlclist.xml" createIfNotExist="False">
    <replace line="</Paths>" condition="Mask"><Item>dlcpacks:\replacedline&lt;/Item></replace>
    </text>
    </archive>

    Hi,

    I gave it a try, and I can't get it to recognize the line I am after (to change), as I'm not sure how to point to it (the "/Paths" in your example.)

    Here is an example of the script:

    <UltimateBackup>
    <LocalPatrol>
    <LosSantosCity>
    <VehicleSet>
    <Vehicles>
    <Vehicle chance="40" pax="1" pax_chance="20">lsps1</Vehicle>
    <Vehicle chance="10" pax="1" pax_chance="20">lsps3</Vehicle>
    <Vehicle chance="10" pax="1" pax_chance="20">lsps4</Vehicle>
    <Vehicle chance="10" pax="1" pax_chance="20">lsps5</Vehicle>
    <Vehicle chance="25" pax="1" pax_chance="20">lsps6</Vehicle>
    <Vehicle chance="5" pax="1" pax_chance="20">lsps7</Vehicle>
    </Vehicles>
    <Peds>
    <Ped chance="20" comp_beard="1" comp_accessories="57" comp_hands="53" comp_eyes="9" comp_pants="36" comp_shirt="5" comp_shirtoverlay="201" comp_shoes="52" comp_decals="13" tex_decals="2" comp_tasks="1">mp_m_freemode_01</Ped>
    <Ped chance="20" comp_beard="1" comp_accessories="57" comp_hands="53" comp_eyes="9" comp_pants="36" comp_shirt="5" comp_shirtoverlay="194" comp_shoes="52" comp_decals="13" tex_decals="2" comp_tasks="14">mp_m_freemode_01</Ped>
    <Ped chance="20" comp_beard="1" comp_accessories="57" comp_hands="53" comp_eyes="9" comp_pants="36" comp_shirt="1" comp_shirtoverlay="191" comp_shoes="52" comp_decals="16" tex_decals="2" comp_tasks="14">mp_m_freemode_01</Ped>
    <Ped chance="20" comp_beard="1" comp_accessories="57" comp_hands="1" comp_eyes="9" comp_pants="36" comp_shirt="39" comp_shirtoverlay="155" tex_shirtoverlay="2" comp_shoes="52" comp_decals="1" comp_tasks="29">mp_m_freemode_01</Ped>
    <Ped chance="5" comp_accessories="34" comp_hands="53" comp_eyes="9" comp_pants="35" comp_shirt="4" comp_shirtoverlay="203" comp_tasks="1" comp_decals="12" tex_decal="2" comp_shoes="53">mp_f_freemode_01</Ped>
    <Ped chance="5" comp_accessories="34" comp_hands="53" comp_eyes="9" comp_pants="35" comp_shirt="4" comp_shirtoverlay="196" comp_tasks="1" comp_decals="12" tex_decal="2" comp_shoes="53">mp_f_freemode_01</Ped>
    <Ped chance="5" comp_accessories="34" comp_hands="53" comp_eyes="9" comp_pants="35" comp_shirt="15" comp_shirtoverlay="193" comp_tasks="1" comp_decals="15" tex_decal="2" comp_shoes="53">mp_f_freemode_01</Ped>
    <Ped chance="5" comp_accessories="34" comp_hands="49" comp_eyes="9" comp_pants="35" comp_shirt="37" comp_shirtoverlay="152" tex_shirt_overlay="2" comp_tasks="31" comp_decals="1" comp_shoes="53">mp_f_freemode_01</Ped>
    </Peds>
    <NonLethals>
    <NonLethal chance="90">WEAPON_STUNGUN</NonLethal>
    <NonLethal>WEAPON_NIGHTSTICK</NonLethal>
    </NonLethals>
    <HandGuns>
    <HandGun>WEAPON_PISTOL</HandGun>
    <HandGun chance="10">WEAPON_COMBATPISTOL</HandGun>
    </HandGuns>
    <LongGuns>
    <LongGun chance="0">WEAPON_CARBINERIFLE</LongGun>
    <LongGun chance="100">WEAPON_PUMPSHOTGUN</LongGun>
    </LongGuns>
    </VehicleSet>
    </LosSantosCity>
    </LocalPatrol>
    </UltimateBackup>

    Now, let's say I want to replace the first "ped" line's chance from "20" to "5" and the last "ped" line's "chance" from "5" to "20"

    I tried something like this:
    <text path="Plugins\LSPDFR\UltimateBackup\DefaultRegions.xml" createIfNotExist="False">
    <replace line="</UltimateBackup/LocalPatrol/LosSantosCity/VehicleSet/Peds>"



  • But that doesn't work...

    Any ideas?



  • @CaptConfuzed
    I think you'll have to turn your path in the replace line into 'gobbledygook' (lol, ie the correct path/folder structure syntax for xml) to get it to work. :thumbsup: It didn't work for me either if I used normal plain text folder structure in the lines.

    This sort of stuff:

    	&lt;Item&gt;dlcpacks:\replacedline\&lt;/Item&gt;
    

    All the '&lt' & '&gt' sorta stuff in the correct place etc. Ah, just realised something

    This forum converts gobbledygook into what it actually is:

    Example 01:
    ie, this (entered in code block):

    	&lt;Item&gt;dlcpacks:\replacedline\&lt;/Item&gt;
    

    becomes this (if entered in plain text/no code block):

    <Item>dlcpacks:\replacedline&lt;/Item>

    Note: the site has messed up the last '&lt' but if done slowly one little bit at a time could at least give you an idea of what the gobbledygook means (if you don't know already?). It also gets a little confused if you have more than one example in the same post so I'll have to post a new post to show you another example.

    Also, are you sure '/UltimateBackup/LocalPatrol/LosSantosCity/VehicleSet/Peds' is a line inside the '.xml' file? Looks like you are mis-using that replace line to target a folder structure? What you put in the replace line is the exact text string inside the file that you want to replace (converted to the correct syntax of course).



  • @CaptConfuzed
    This

    	&lt;Item&gt;
    

    Becomes
    <Item>

    Seems like it only wants to work some of the time or if the plain text part is pasted first (site formatting issue) but has given me another (possibly good, we'll see) idea....brb



  • @CaptConfuzed

    Try this (Edit: Ignore this. See 'SOLUTION:' in last post instead):

    <text path="Plugins\LSPDFR\UltimateBackup\DefaultRegions.xml" createIfNotExist="False">
    <replace line="&lt;/UltimateBackup/LocalPatrol/LosSantosCity/VehicleSet/Peds&gt;" condition="Mask">what you want to replace with here also written in gobbledygook</replace>
    

    Note: I'm not confident your '<replace line', this:

    '</UltimateBackup/LocalPatrol/LosSantosCity/VehicleSet/Peds>'

    is actually in the file (can you confirm it is?) you want to replace the text string of, so we may need to edit that line to the correct data. If you post the .xml to Pastebin & tell me exactly what you want to replace within the file & exactly what you want to replace it with I will be able to give you better examples :thumbsup:

    I used this XML Escape / Unescape Converter to quickly & easily convert between plain text & xml :thumbsup:

    Gonna conduct a few tests of my own...brb



  • @CaptConfuzed
    Right, I've discovered a few things :thumbsup:

    I tried replacing multiple lines in 'dlclist.xml' & can confirm that it is definitely possible :thumbsup:

      <content>
        <archive path="update\update.rpf" createIfNotExist="False" type="RPF7">
          <text path="common\data\dlclist.xml" createIfNotExist="False">
            <replace line="*&lt;Item&gt;dlcpacks:\vans123\&lt;/Item&gt;*" condition="Mask">replace03test</replace>
            <replace line="*&lt;Item&gt;dlcpacks:\250gto62\&lt;/Item&gt;*" condition="Mask">replace01test</replace>
            <replace line="*&lt;Item&gt;dlcpacks:\mustangmach1\&lt;/Item&gt;*" condition="Mask">replace02test</replace>
          </text>
        </archive>
      </content>
    

    In this 'dlclist.xml' example just above, this:

    		<Item>dlcpacks:/iaabreakableglass/</Item>
    		<Item>dlcpacks:\69charger\</Item>
    		<Item>dlcpacks:\mustangmach1\</Item>
    		<Item>dlcpacks:\250gto62\</Item>
    		<Item>dlcpacks:\66fastback\</Item>
    		<Item>dlcpacks:\vans123\</Item>
    	</Paths>
    </SMandatoryPacksData>
    

    then ends up looking like this:

    		<Item>dlcpacks:/iaabreakableglass/</Item>
    		<Item>dlcpacks:\69charger\</Item>
    replace02test
    replace01test
    		<Item>dlcpacks:\66fastback\</Item>
    replace03test
    	</Paths>
    </SMandatoryPacksData>
    

    Yeah, I don't know how to make it pretty yet lol

    =======================

    For the:

    <replace line="*&lt;/Paths&gt;*"
    

    part you mentioned having trouble with, you would first copy the line of text you want to find & then run it through the XML Escape / Unescape Converter just to make sure it is in the correct format (paste it in the top box & then hit the [Escape] button. A few seconds later the correct string will appear in the second box. Copy the new text & paste it into the first part of the '<replace line' between the:

    "* & *" symbols in the line (ie between the quote(") star(*) & star(*) quote(") symbols that are in that order). 
    

    (Note: If there is no symbol convertion in the Escape Converter the lines will look the same. Play about typing various things into the first box & hitting [Escape] & you'll see what I mean. It only converts certain symbols, the ones required for the correct syntax :thumbsup:)

    Taken from Escape Converter page:
    The following characters are reserved in XML and must be replaced with their corresponding XML entities:

    ' is replaced with &apos;
    " is replaced with &quot;
    & is replaced with &amp;
    < is replaced with &lt;
    > is replaced with &gt;
    

    Anything else doesn't need converted as far as I can tell.

    One problem I have noticed though, is that I'm not sure how to make the '.oiv' edit files outside of a '.rpf'. Say, your 'Plugins\LSPDFR\UltimateBackup\DefaultRegions.xml' path for example. I'm not sure if the '.oiv' would be able to find that (without some other editing to the format of 'assembly.xml' to point it in the right direction)? Tests I have conducted have failed so far :slight_frown:
    If I can find a mod that does similar & have a look at the way it is written I'll have a better idea of how to format it :thumbsup:.



  • @CaptConfuzed
    SOLUTION:
    Little bit of guess work & a whole heap of luck later & I think I have what you need :thumbsup:

    I manually created the folder structure & placed a 'DefaultRegions.xml' file here:

    ...Grand Theft Auto V\Plugins\LSPDFR\UltimateBackup\DefaultRegions.xml (correct? Made a guess)

    & made the inside of the file look like this (just for testing):

    <?xml version="1.0" encoding="UTF-8"?>
    Testline01original
    Testline02original
    Testline03original
    

    I then created an '.oiv' with just an empty 'content' folder (vital) & an 'assembly.xml' that looked like this inside:

    =========================

    <?xml version="1.0" encoding="UTF-8"?>
    <package version="2.0" id="{BC759B87-3DDD-4E96-A6BF-371863AF59D0}" target="Five">
      <metadata>
        <name>Test Replace Text String In xml File</name>
        <version>
          <major>1</major>
          <minor>0</minor>
        </version>
        <author>
          <displayName>a63nt 5m1th</displayName>
        </author>
        <description>
          <![CDATA[Auto Installer Features :
    ---------------------------
    • Automated syntax replace in "Grand Theft Auto V\Plugins\LSPDFR\UltimateBackup\DefaultRegions.xml" √
    • No other game files or archives will be replaced or modified. √
    
    → Choose Game folder in Next Step! 
    
    ≔≔≔≔≔≔≔≔≔≔≔≔≔≔≔
    Changelog V1.0:
    ≔≔≔≔≔≔≔≔≔≔≔≔≔≔≔
    
    Pure blind luck this
    
    
    ]]>
        </description>
      </metadata>
      <colors>
        <headerBackground useBlackTextColor="True">$FFFFFF</headerBackground>
        <iconBackground>$FFFFFF</iconBackground>
      </colors>
      <content>
          <text path="Plugins\LSPDFR\UltimateBackup\DefaultRegions.xml" createIfNotExist="False">
            <replace line="*Testline01original*" condition="Mask">replace01test</replace>
            <replace line="*Testline02original*" condition="Mask">replace02test</replace>
            <replace line="*Testline03original*" condition="Mask">replace03test</replace>
          </text>
      </content>
    </package>
    

    =========================

    I then ran the '.oiv' by double clicking on it, installing it with OpenIV & it successfully changed the contents of 'DefaultRegions.xml' to this:

    <?xml version="1.0" encoding="UTF-8"?>
    replace01test
    replace02test
    replace03test
    

    Note: As the text I was replacing doesn't have any of the symbols required to be converted by the XML Escape / Unescape Converter I did not use it. You will most likely have to. Just don't forget about it :thumbsup:

    The '.oiv' I created will fail for the reason mentioned below if you try to run it on your setup but if you put the 'Testline01original' (01,02 & 03 etc) lines somewhere inside your 'DefaultRegions.xml' (make a backup first) & I have guessed the file structure correctly (easy enough to edit if not), you'll see the changes it makes :thumbsup:

    Extra:
    One thing I did notice back in the early testing of this is that if the text string you intend to replace is not in the file you intend to edit, the installer will say it failed with an installation error. So you might want to warn your users of that :thumbsup: Don't edit these lines ever, on fear of death etc.

    If I remember right, even if it says install failed, it replaces what it can find & only really warns you that there was something that it didn't find & asks you to check the log. So not a complete 'nothing is installed, dead in the water' install failure, just a 'something wasn't quite right there. Make sure all the lines exist in the file' one :thumbsup:.

    Another observation I've made is that you want to make each line you may want to edit unique. So you can target only that line when you update & not have the '.oiv' replace 2 identical lines when you only want it to change one of them. The way your lines have a lot of variation in them it should be quite easy to select just one line but I thought I'd mention it as something to keep in mind for possible future projects etc.

    I'm calling this a resounding success anyway. Never thought when I dropped you the initial message I'd get anywhere near a solution for you :slight_smile: :thumbsup:

    All that is required to do now is adapt the process to your specific needs. I'm confident I'll be able to help with that (now). If you have any trouble with it, just give me a shout :thumbsup:



  • @a63nt-5m1th Thanks so much!
    I will take a look at this when I get a chance - I've been busy holidaying :blush:



  • @CaptConfuzed
    :slight_smile: Enjoy your holiday mate. It'll be here when you get back :thumbsup:


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.