• If you have a mod, tool or prefab, please use the Resources section. Click Mods at the top of the forums.

XPath Modding Explanation Thread

This is a large amount of information in these posts. I'll be working on a full, properly formed tutorial as we get access to A17 and we can really make the xpath system shine. I've listed some examples here, and we'll be posting a ton more xpath samples over the coming weeks, as we port the SDX modlets over to use the native hooks.

By all means, begin posting your comments, questions, or requests for clarity.

Since we now know that xpath support will be built-into the vanilla base game, and discussions earlier were getting a bit confusing, I've decided to make a new thread to try to demystify xpath and what it'll mean for mods and modders going forward in A17. The information in this thread has been pieced together from forum and discord discussions. They may not be 100% accurate, but I will update this thread when we know the full implementation.

XPath is a way of adding, changing, or removing XML lines and nodes, without directly editing the XML files. It allows you to apply patches to the XML files without manually editing the vanilla XML files.

SDX has had partial support for this since its initial release, and a lot of the SDX Modlets are already written this way. We will be using some of the SDX's xpath as examples in this thread, but SDX is not required to do this in A17 and onwards.

I believe in using examples to explain concept, so in the next few posts, you'll see a mixture of explanation, along with sample xpath code.

The following Mod structure is expected for A17 and beyond:

Code:
Mods/
   <ModName>/
       Config/
       UIAtlases/ItemIconAtlas/
       ModInfo.xml

   <ModName2>/
       Config/
       ModInfo.xml
You will be able to have multiple mods loaded, and loading will occur as long as the ModInfo.xml exists. This is unchanged from what we've been doing doing with other alphas, with the exception of the Config folder.

This Config folder will support loading XML files, written using xpath, in the following folder structure:

Code:
Config/entityclasses.xml
Config/gamestages.xml
Config/items.xml
The files in the Config folder will not be a full copy of the vanilla file with your changes. Rather, it'll contain the changes you want done to the vanilla files. The files under the Config must match the vanilla file name. You cannot create an entityclasses2.xml file, and expect it to work. Any changes in the entityclasses.xml will have to be done in the same file. However, each mod can have its own entityclasses.xml.

During the game's initialization, it will perform the xpath merge in-memory only; no files will be actually be modified. This would allow us to remove mods we no longer want, without re-validating against steam, or previous copies of the xml. That's a big one. No more half merging of a mod, and not having it work, then trying to pull it back out.

What this means for us is that we'll be able to make a variety of smaller mods, which I've been calling modlets, which can add, remove and change smaller pieces of the game. They can be used together, or they could be added to an overhaul mod, in order to style your game play easier.

These modlets would also exists outside of the Data/Config folder, so if you have made direct XML changes in your Alpha 17.1 Data/Config files, and Steam updated the game to 17.2, you would have lost your changes, or would have to re-merge them in. We've all been there before. But if they existed as modlets, under the Mods folder, they would be safe. And as long as your xpath is still valid to the new XML, it should load up with no additional work on your part.

If we could use xyth's JunkItems modlet, which adds random, scrappable junk items to loot containers, and add them to Valmod Overhaul. Likewise, if Valmod Overhaul did not have the No Ammo modlet (which gives you the ability to unload a gun and get its bullets back without disassembling it), you could drop the NoAmmo modlet into your Mods folder. Headshots only? Want to increase stack sizes? Same deal.

With a properly constructed modlet, we'll be able to piece together new play styles for people to enjoy and share. A modder working on a large overhaul won't have to duplicate work. If they wanted to include the No Ammo mod, they wouldn't have to code it themselves, letting them focus on the bits that make their mod really unique.

Let's get started on your journey...

 
Last edited by a moderator:
Perfect, that is what I was missing in this case. However, some blocks have drop event="destroy", some have drop event="disassemble", and some have the drop event="Harvest" any ideas how I would point out those paths?

 
Perfect, that is what I was missing in this case. However, some blocks have drop event="destroy", some have drop event="disassemble", and some have the drop event="Harvest" any ideas how I would point out those paths?
You can do multi-conditionals

Code:
<set xpath="/blocks/block[@name='woodLogPillar100']/drop[@name='resourceWood' and @event='Harvest']/@count">600</set>
 
Could you please help me with something, I'm new to this modding and I have been trying to make a mod which makes the Iron Hoe faster but I keep getting syntax error

Code:

<set xpath="/items/item[@name=meleeToolHoeIron]/property[@class=Action1]/property[@name'Delay']/@value">0.05

<set>

EDIT:After reading a few post before, I manage to find out where I was wrong :positive: , but thanks anyway for making this modding tutorial :angel:

 
Last edited by a moderator:
Could you please help me with something, I'm new to this modding and I have been trying to make a mod which makes the Iron Hoe faster but I keep getting syntax error
Code:

<set xpath="/items/item[@name=meleeToolHoeIron]/property[@class=Action1]/property[@name'Delay']/@value">0.05

<set>

EDIT:After reading a few post before, I manage to find out where I was wrong :positive: , but thanks anyway for making this modding tutorial :angel:
Glad you were able to figure it out. :)

 
so I created a modlet and have a new item I appended to items.xml. I want to create an icon for it.

1. is there an icon tutorial? like size, file type, location it goes, etc.

2. will a player need to install anything or can I just put the mod and icon on the server?

 
so I created a modlet and have a new item I appended to items.xml. I want to create an icon for it.
1. is there an icon tutorial? like size, file type, location it goes, etc.

2. will a player need to install anything or can I just put the mod and icon on the server?
Icon size right now is 116x80. I *think* the A18 HD ones are 116x116, could be wrong. Create a folder in your mod folder called ItemIcons. Place them in there. I know png and jpg work for sure. Maybe others.

Any mod that contains anything more than just xmls has to be installed on the server and client both. Resources, icons, localization will not push from the server.

 
hello everyone,

i tried to create a modlet which went good so far but i want to add another tag at the progression xml.

For example at the perk living of the land i want to add the tag chocolateseeds but i got no idea how to write that down. Do I have to use append, set or setattribute for this to work? And how does the line actually look if its done right.

I tried a lot but coudnt figure out right typing.

 
...i need to remove these T5 quest from vanilla quests.xml: https://i.imgur.com/cSOOrT2.png

Code:
   <quest_list id="trader_quests">
       <!-- Tier 1 -->
           <quest id="tier1_clear" />
           <quest id="tier1_fetch" />
           <quest id="tier1_buried_supplies" />
       <!-- Tier 2 -->
           <quest id="tier2_clear" />
           <quest id="tier2_fetch" />
           <quest id="tier2_hidden_cache" />
           <quest id="tier2_fetch_clear" />
       <!-- Tier 3 -->
           <quest id="tier3_clear" />
           <quest id="tier3_fetch" />
           <quest id="tier3_hidden_cache" />
           <quest id="tier3_fetch_clear" />
           <quest id="tier3_hidden_clear" />
       <!-- Tier 4 -->
           <quest id="tier4_clear" />
           <quest id="tier4_fetch" />
           <quest id="tier4_hidden_cache" />
           <quest id="tier4_fetch_clear" />
           <quest id="tier4_hidden_clear" />    
       <!-- Tier 5 -->
           <quest id="tier5_clear" />
           <quest id="tier5_fetch" />
           <quest id="tier5_hidden_cache" />
           <quest id="tier5_fetch_clear" />
           <quest id="tier5_hidden_clear" />
       <!-- Tier 6 -->
           <!--    <quest id="tier6_clear" /> -->
           <!--    <quest id="tier6_fetch" /> -->
           <!--    <quest id="tier6_hidden_cache" /> -->
           <!--    <quest id="tier6_fetch_clear" /> -->
           <!--    <quest id="tier6_hidden_clear" /> -->
   </quest_list>
This is what i got, but doubt it's right, and i can't test it right now:

Code:
<configs>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_clear']"/>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_fetch']"/>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_hidden_cache']"/>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_fetch_clear']"/>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_hidden_clear']"/>
</configs>
this is to bypass a game-breaking bug found here: https://7daystodie.com/forums/showthread.php?122290-KeyNotFoundException

 
Last edited by a moderator:
...i need to remove these T5 quest from vanilla quests.xml: https://i.imgur.com/cSOOrT2.png

Code:
   <quest_list id="trader_quests">
       <!-- Tier 1 -->
           <quest id="tier1_clear" />
           <quest id="tier1_fetch" />
           <quest id="tier1_buried_supplies" />
       <!-- Tier 2 -->
           <quest id="tier2_clear" />
           <quest id="tier2_fetch" />
           <quest id="tier2_hidden_cache" />
           <quest id="tier2_fetch_clear" />
       <!-- Tier 3 -->
           <quest id="tier3_clear" />
           <quest id="tier3_fetch" />
           <quest id="tier3_hidden_cache" />
           <quest id="tier3_fetch_clear" />
           <quest id="tier3_hidden_clear" />
       <!-- Tier 4 -->
           <quest id="tier4_clear" />
           <quest id="tier4_fetch" />
           <quest id="tier4_hidden_cache" />
           <quest id="tier4_fetch_clear" />
           <quest id="tier4_hidden_clear" />    
       <!-- Tier 5 -->
           <quest id="tier5_clear" />
           <quest id="tier5_fetch" />
           <quest id="tier5_hidden_cache" />
           <quest id="tier5_fetch_clear" />
           <quest id="tier5_hidden_clear" />
       <!-- Tier 6 -->
           <!--    <quest id="tier6_clear" /> -->
           <!--    <quest id="tier6_fetch" /> -->
           <!--    <quest id="tier6_hidden_cache" /> -->
           <!--    <quest id="tier6_fetch_clear" /> -->
           <!--    <quest id="tier6_hidden_clear" /> -->
   </quest_list>
This is what i got, but doubt it's right, and i can't test it right now:

Code:
<configs>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_clear']"/>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_fetch']"/>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_hidden_cache']"/>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_fetch_clear']"/>
   <remove xpath="/quests/quest_list[@id='trader_quests']//quest[@id='tier5_hidden_clear']"/>
</configs>
this is to bypass a game-breaking bug found here: https://7daystodie.com/forums/showthread.php?122290-KeyNotFoundException
That should work. Are you getting any errors or warnings in your output_log.txt of it not applying?

 
Hi,It's me again :wave:

This time I need help on how to change the dry time of the concrete block on both the reinforce and the normal one, I been doing some digging but came up with nothing :upset: ,So before I change every value I see :tongue: , I would like to ask you for help!

 
Hi,It's me again :wave: This time I need help on how to change the dry time of the concrete block on both the reinforce and the normal one, I been doing some digging but came up with nothing :upset: ,So before I change every value I see :tongue: , I would like to ask you for help!
Hi,

To change the drying speed of concrete you need to change the values for UpgradeRated.Rate under pouredConcreteMaster and pouredRConcreteMaster blocks in blocks.xml file.

It appears that it dries fastest when the value is 1 (default value is 4 and 5 respectively). I have tried lower values but decimals (e.g. 0.5) give an error and the world fails to load and 0 or negative values didn't seem to be any different from 1. Someone please correct me if there are any values which make it even faster.

Alternatively to editing the file yourself, you can download my mod which I have created just now and which does exactly that: https://www.nexusmods.com/7daystodie/mods/406

Here's the code that my mod uses.

Code:
<configs>
<set xpath="/blocks/block[@name='pouredConcreteMaster']/property[@name='UpgradeRated.Rate']/@value">1</set>
<set xpath="/blocks/block[@name='pouredRConcreteMaster']/property[@name='UpgradeRated.Rate']/@value">1</set>
</configs>
 
Hi,

I have a question regarding the xpath command remove.

Is it possible to remove only a part of a string in an attribute?

For example, Advanced Engineering skill level 2 teaches these recipes:

gunPistol,gunPumpShotgun,gunHuntingRifle,spotlightPlayer,speaker,pressureplate,pressureplateLong,electrictimerrelay,motionsensor,cementMixer,ammoDartSteel,dartTrap

Code:
<passive_effect name="RecipeTagUnlocked" operation="base_set" value="1" level="2,5" tags="gunPistol,gunPumpShotgun,gunHuntingRifle,spotlightPlayer,speaker,pressureplate,pressureplateLong,electrictimerrelay,motionsensor,cementMixer,ammoDartSteel,dartTrap" />
Is is possible to use the remove command to remove only a single recipe from this skill? I tried to format the remove command in a similar fashion as append command but that didn't work.

Code:
<remove xpath="/progression/perks/perk[@name='perkAdvancedEngineering']/effect_group/passive_effect[@name='RecipeTagUnlocked' and @level='2,5']/@tags">,dartTrap</remove>
Or do I have to use the set command and set it to the same string but without the one recipe that I don't want there?

Code:
<set xpath="/progression/perks/perk[@name='perkAdvancedEngineering']/effect_group/passive_effect[@name='RecipeTagUnlocked' and @level='2,5']/@tags">gunPistol,gunPumpShotgun,gunHuntingRifle,spotlightPlayer,speaker,pressureplate,pressureplateLong,electrictimerrelay,motionsensor,cementMixer,ammoDartSteel</set>
Is there any other command which can remove only a specific part of the string?

Thanks.

 
could you add a page explaining how to use different Xpath functions such as pulling a numerical value from the vanilla files, and multiplying them by 2, and then setting that multiplication as the new value?

 
Hi,
I have a question regarding the xpath command remove.

Is it possible to remove only a part of a string in an attribute?

For example, Advanced Engineering skill level 2 teaches these recipes:

gunPistol,gunPumpShotgun,gunHuntingRifle,spotlightPlayer,speaker,pressureplate,pressureplateLong,electrictimerrelay,motionsensor,cementMixer,ammoDartSteel,dartTrap

Code:
<passive_effect name="RecipeTagUnlocked" operation="base_set" value="1" level="2,5" tags="gunPistol,gunPumpShotgun,gunHuntingRifle,spotlightPlayer,speaker,pressureplate,pressureplateLong,electrictimerrelay,motionsensor,cementMixer,ammoDartSteel,dartTrap" />
Is is possible to use the remove command to remove only a single recipe from this skill? I tried to format the remove command in a similar fashion as append command but that didn't work.

Code:
<remove xpath="/progression/perks/perk[@name='perkAdvancedEngineering']/effect_group/passive_effect[@name='RecipeTagUnlocked' and @level='2,5']/@tags">,dartTrap</remove>
Or do I have to use the set command and set it to the same string but without the one recipe that I don't want there?

Code:
<set xpath="/progression/perks/perk[@name='perkAdvancedEngineering']/effect_group/passive_effect[@name='RecipeTagUnlocked' and @level='2,5']/@tags">gunPistol,gunPumpShotgun,gunHuntingRifle,spotlightPlayer,speaker,pressureplate,pressureplateLong,electrictimerrelay,motionsensor,cementMixer,ammoDartSteel</set>
Is there any other command which can remove only a specific part of the string?

Thanks.
I don't think its possible. XPath itself is just a method of referencing XML nodes and attributes, and the game's own settings control what it can do with that information. Remove itself removes a node or attribute, but not a sub-string value. Append can add a sub-string, but I don't think its possible to remove one.

 
could you add a page explaining how to use different Xpath functions such as pulling a numerical value from the vanilla files, and multiplying them by 2, and then setting that multiplication as the new value?
I don't think this is possible either. While you can do math in an xpath evaluation, there isn't a way for us to take the new value it calculates and add it to the @value.

The xpath="" finds the node, then the game takes the <set, <append, etc and replaces the node or attribute with the >NEED THE CALCULATED VALUE HERE<. Inside those > <, there isn't support for an xpath statement.

Code:
<set xpath="/myNod/price">NEED THE CALCULATED VALUE HERE</set>
 
Back
Top