• 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:
@METALmurderer Looks like you're missing quotes at the end of your first append tags. The error messages are helpful for locating mistakes, in this case "cannot contain '<' Line 95, position 55." Not sure what you're using to edit but Notepad++ shows line numbers on the left side.

Code:
<append xpath="/items/item[@name='ammoArrowFlaming'][color="#EE82EE"]"[/color]><property name="Stacknumber" value="250"/></append>
<append xpath="/items/item[@name='ammoCrossbowBoltExploding'][color="#EE82EE"]"[/color]><property name="Stacknumber" value="250"/></append>
Also thank you much Swiftpaw for the exportcurrentconfigs command. I was just wondering earlier today how to view the post-change XMLs.

 
Last edited by a moderator:
@METALmurderer Looks like you're missing quotes at the end of your first append tags. The error messages are helpful for locating mistakes, in this case "cannot contain '<' Line 95, position 55." Not sure what you're using to edit but Notepad++ shows line numbers on the left side.

Code:
<append xpath="/items/item[@name='ammoArrowFlaming'][color="#EE82EE"]"[/color]><property name="Stacknumber" value="250"/></append>
<append xpath="/items/item[@name='ammoCrossbowBoltExploding'][color="#EE82EE"]"[/color]><property name="Stacknumber" value="250"/></append>
Also thank you much Swiftpaw for the exportcurrentconfigs command. I was just wondering earlier today how to view the post-change XMLs.
Thanks, I suppose I was just staring at the code too long to miss something that simple...

 
is there a way to "replace" an old mesh from a tool with a new only per xpath ?

So maybe i have made a new steel pickaxe model and will use it as a replace for the vanilla one

possible to change :

<property name="Meshfile" value="Items/Tools/pickaxe_steelPrefab"/>

to

<property name="Meshfile" value="#@modfolder:Resources/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel"/>

only ?

via modlet ?

 
is there a way to "replace" an old mesh from a tool with a new only per xpath ?
So maybe i have made a new steel pickaxe model and will use it as a replace for the vanilla one

possible to change :

<property name="Meshfile" value="Items/Tools/pickaxe_steelPrefab"/>

to

<property name="Meshfile" value="#@modfolder:Resources/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel"/>

only ?

via modlet ?
Yup, using <set

Code:
<set xpath="items/item[@name='toolsPickAxe']/property[@name='Meshfile']/@value">#@modfolder:Resouces/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel</set>
that's assuming you have a Mods/YourFolder/Resources/meleeToolPickAxeSteel.unity3d exists.

 
hay guy what would the xpath code be to remove the HUDLeftStatBars?
This should do it:

Filename: Mods/YourMod/Config/XUi/xui.xml

Code:
<configs>
    <remove xpath="/xui/ruleset/window_group/window[@name='HUDLeftStatBars']" />
</configs>
 
This should do it:
Filename: Mods/YourMod/Config/XUi/xui.xml

Code:
<configs>
    <remove xpath="/xui/ruleset/window_group/window[@name='HUDLeftStatBars']" />
</configs>
thank you.

I'm looking to take it out of windows xml to add a new one in. sorry for the confusion.

 
Last edited by a moderator:
thank you.
I'm looking to take it out of windows xml to add a new one in. sorry for the confusion.
Filename: Mods/YourMod/Config/XUi/windows.xml

Code:
<configs>
    <remove xpath="/windows/window[@name='HUDLeftStatBars']" />
    <append xpath="/windows" >
              <window name="HUDLeftStatBars" >

               </window>
   </append>
</configs>
 
Yup, using <set

Code:
<set xpath="items/item[@name='toolsPickAxe']/property[@name='Meshfile']/@value">#@modfolder:Resouces/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel</set>
that's assuming you have a Mods/YourFolder/Resources/meleeToolPickAxeSteel.unity3d exists.
so the "toolsPickAxe" part in this code is the name of the item, right ?

so if it is called "meleeToolPickaxeSteel" the code has to be this :

Code:
<set xpath="items/item[@name='meleeToolPickaxeSteel']/property[@name='Meshfile']/@value">#@modfolder:Resouces/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel</set>
 
so the "toolsPickAxe" part in this code is the name of the item, right ?
so if it is called "meleeToolPickaxeSteel" the code has to be this :

Code:
<set xpath="items/item[@name='meleeToolPickaxeSteel']/property[@name='Meshfile']/@value">#@modfolder:Resouces/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel</set>
Whatever it is in the XML. I usually not in a position to cross reference the particular names; they are usually just to get you started.

 
Whatever it is in the XML. I usually not in a position to cross reference the particular names; they are usually just to get you started.

i use this code

Code:
	<append xpath="/items">

<set xpath="items/item[@name='meleeToolPickaxeSteel']/property[@name='Meshfile']/@value">#@modfolder:Resouces/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel</set>

</append>
but it dont work, i have NO error in the log but ingame is still the same old model

 
what's up all, I need some help, im trying to have the hunting rifle 3 rounds in stud of 1, and add new ammo.

I have the ammo in but cant get it to load in this is what im using. does these need to go at the top of the xml?

Code:
<set xpath="/items/item[@name='gunHuntingRifle']/property[@class='Action1']/passive_effect[@name='MagazineSize'][@value='1']/@value">3</set>
<set xpath="/items/item/property[@class='Action0']/property[@name='Magazine_items'][@value='ammo9mmBullet,ammo9mmBulletSteel']/@value">ammo9mmBullet,ammo9mmBulletSteel,ammo9mmBulletExp</set>
-- up date --

got the ammo to load but when I spawned in a zombie I couldn't move, I died and I could move again but my fire Butten was reload and no ammo was being loaded. here is my ammo code.

Code:
<item name="ammo9mmBulletExp">
<property name="DisplayType" value="ammoBullet"/>
<property name="HoldType" value="45"/>
<property name="Meshfile" value="Items/Misc/sackPrefab"/>
<property name="DropMeshfile" value="Items/Misc/sack_droppedPrefab"/>
<property name="Material" value="Mbrass"/>
<property name="Stacknumber" value="500"/> <!-- STK ammo -->
<property name="CraftingSkillGroup" value="craftSkillGuns"/>
<property name="EconomicValue" value="14"/>
<property name="Group" value="Ammo/Weapons"/>
<property class="Action1">
	<property name="Class" value="Projectile"/>
	<property name="Gravity" value="-7"/>
	<property name="Explosion.ParticleIndex" value="4"/> <!-- which Prefab/particle is used -->
	<property name="Explosion.RadiusBlocks" value="2"/> <!-- damage radius for blocks -->
	<property name="Explosion.BlockDamage" value="75"/> <!-- damage for blocks in the center of the explosion -->
	<property name="Explosion.RadiusEntities" value="2"/> <!-- damage radius for entities -->
	<property name="Explosion.EntityDamage" value="50"/> <!-- damage for entities in the center of the explosion. Zombies take 2x this damage. -->
       <property name="Explosion.DamageBonus.stone" value="15"/>
	<property name="Explosion.DamageBonus.metal" value="7"/>
	<property name="Explosion.DamageBonus.earth" value="25"/> <!-- should work? -->
	<property name="Explosion.DamageBonus.wood" value="35"/>
	<property name="Explosion.DamageBonus.water" value="0"/>
</property>
<property name="CraftingSkillGroup" value="craftSkillScience"/>
<property name="Group" value="Ammo/Weapons"/>
<effect_group name="Base Effects" tiered="false">
	<passive_effect name="EntityDamage" operation="base_set" value="25"/>
	<passive_effect name="BlockDamage" operation="base_set" value="7"/>
	<passive_effect name="ProjectileVelocity" operation="base_set" value="60"/>
	<display_value name="ExRadius" value="5" />
</effect_group>
</item>
 
Last edited by a moderator:
i use this code

Code:
	<append xpath="/items">

<set xpath="items/item[@name='meleeToolPickaxeSteel']/property[@name='Meshfile']/@value">#@modfolder:Resouces/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel</set>

</append>
but it dont work, i have NO error in the log but ingame is still the same old model
I think you need to move <set> outside of <append></append>, else you are telling the game to add the <set> string to the xml file instead of changing the given values in the file :)

Code:
 <set xpath="/items/item[@name='meleeToolPickaxeSteel']/property[@name='Meshfile']/@value">#@modfolder:Resouces/meleeToolPickaxeSteel.unity3d?meleeToolPickaxeSteel</set>

<append xpath="/items">
<!-- whatever you want to add goes here, else the append command is not needed-->
</append>
You were also missing a / at <set xpath="items/item...> :)

 
Can anyone tell me what's wrong with this xpath please?

<set xpath="/progression/level/@exp_to_level">100</set>

If it's obvious I apologise. The 100 shows in black text, the rest shows purple (except xpath which is in red). It seems to me like it should work but... no. Aim: trying to reduce the experience needed to level up.

Any help appreciated.

 
Can anyone tell me what's wrong with this xpath please?
<set xpath="/progression/level/@exp_to_level">100</set>

If it's obvious I apologise. The 100 shows in black text, the rest shows purple (except xpath which is in red). It seems to me like it should work but... no. Aim: trying to reduce the experience needed to level up.

Any help appreciated.
Yup, that looks right. Are you getting an error or the change isn't applied?

 
Is it possible to use append to add one node after an existing one? I managed to do what I want using insertafter, but Im curious after I failed with append.

original

Code:
<recipe name="woodFrameBlock" count="1">
<ingredient name="resourceWood" count="2"/>
</recipe>
lets say I want add another ingredient after wood. I feel it's possible to use append, but Im failing to point the right path I guess

Code:
<append xpath="/recipes/recipe[@name='woodFrameBlock']/@recipe">
<ingredient name="resourceNail" count="1"/>
</append>
This will add the code inside recipe node, so its not what I want. If I change to @ingredient, it will add to the wood node. so I tried /ingredient/ without @, because its not inside any of the existing nodes, but it doesnt work.

 
This should work

Code:
<append xpath="/recipes/recipe[@name='woodFrameBlock']">
<ingredient name="resourceNail" count="1"/>
</append>
I think you don't need the /recipes after you are already in the [@name=woodFrameBlock]

 
Back
Top