• 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:
Yes, it's listed as loaded in the server output log, and also in the client connecting to the server. Case hasn't changed between Windows and Linux as I just direct copied the folders over, and then corrected permissions for the server to use them.
I even though maybe it was because I had a couple of spaces in the folder name, but other mods with spaces in the folder are working without an issue.

It's got me completely baffled because based on all available data, the blocks should be in the game. Yet they aren't.

Update: Tested replacing the spaces in the folder names with _, and it's still an issue.

I'm sure eventually I'll figure it out and just facepalm.
Which modlet is it? maybe I can spot something.

 
Hi Every one, I'm trying to add a chemist perk that will add 7 new skills and recipes at different levels
Perk= chemist

skills= Adrenaline_Syringe , ZombrexTablets , EnergyDrink , Health_Syringe , F15PurificationPill , SpeedCapsules , CalciumTablets

they can be moved around

and with the attribute attIntellect. any help would be great thanks

and the line to add a new item and recipes. thanks in advance.
Can you show us what XML code you want, and where you'd like to see it?

 
Which modlet is it? maybe I can spot something.
It's a new admin block I'm making, which I may port into something else for the public. I figured it out, and it was just me missing a step. Didn't use recursive on changing permissions so the xml files were still owned by root. There wasn't any error for files it couldn't access, it just ignored them. So it was loading an empty mod.

 
It's a new admin block I'm making, which I may port into something else for the public. I figured it out, and it was just me missing a step. Didn't use recursive on changing permissions so the xml files were still owned by root. There wasn't any error for files it couldn't access, it just ignored them. So it was loading an empty mod.
Great to hear you got sorted out. Good luck with your modlet.

 
Excuse my ignorance (and that I haven't had time to read the entire thread yet), is this kind of modding dependent on a particular program? Or will notepad++ still be sufficient to mod like changing the old .xml files?

 
I like the 32-bit verison of Notepad++, which comes with a Plugin Manager to allow you to install XML Tools... helps tons when you are working with XML files.

 
Thank you sphereii for this nice tutorial !

Can I append an attribute to element.For example:

from this

Code:
<attribute name="attPerception" name_key="attPerceptionName" desc_key="attPerceptionDesc" icon="ui_game_symbol_stealth">
to this

Code:
<attribute name="attPerception" [b]max_level="1000"[/b] name_key="attPerceptionName" desc_key="attPerceptionDesc" icon="ui_game_symbol_stealth">
I want to do this with every <attribute>

Or I have to replace the whole line. (Can I? I have to replace the whole element with it's sub-elements, don't I?)
You can add/modify an attribute with the setattribute command:

Code:
<setattribute xpath="[color="#FF0000"]PATH[/color]" name="[color="#FF0000"]ATTRIBUTE_NAME[/color]">[color="#FF0000"]VALUE[/color]</setattribute>
Example:

Code:
<setattribute xpath="/progression/attributes/attribute[@name='attPerception']" name="max_level">1000</setattribute>
It might be possible to remove an attribute with the remove command, but so far I got only NullReferenceExceptions with my tests.

Edit: the nullref is unavoidable using the remove command with an attribute.

 
Last edited by a moderator:
Thank you sphereii for this nice tutorial !



You can add/modify an attribute with the setattribute command:

Code:
<setattribute xpath="[color="#FF0000"]PATH[/color]" name="[color="#FF0000"]ATTRIBUTE_NAME[/color]">[color="#FF0000"]VALUE[/color]</setattribute>
Example:

Code:
<setattribute xpath="/progression/attributes/attribute[@name='attPerception']" name="max_level">1000</setattribute>
It might be possible to remove an attribute with the remove command, but so far I got only NullReferenceExceptions with my tests.
That's a new one for me! Thank you! I'll add it as an example.

 
Just did a quick bit of digging through the code to see what is implemented.

In XmlPatcher, the following functions (and their inputs) are called:





case "set":



return _targetFile.SetByXPath(attribute, _patchElement, _patchName) > 0;



case "setattribute":



return _targetFile.SetAttributeByXPath(attribute, _patchElement, _patchName) > 0;



case "append":



return _targetFile.AppendByXPath(attribute, _patchElement, _patchName) > 0;



case "prepend":



return _targetFile.PrependByXPath(attribute, _patchElement, _patchName) > 0;



case "insertBefore":



return _targetFile.InsertBeforeByXPath(attribute, _patchElement, _patchName) > 0;



case "insertAfter":



return _targetFile.InsertAfterByXPath(attribute, _patchElement, _patchName) > 0;



case "remove":



return _targetFile.RemoveByXPath(attribute, _patchName) > 0;



hope that clears things up!

 
So I am diving into this, I'm not all that familiar with XML, but I have been learning Python for a bit. Figured this was way cooler and easier than writing a script to edit stuff. Took my first stab at removing the radiated vultures until the Null Exception is fixed, how did I do? Won't have a chance to test it for a bit.

<config>

<set xpath="/entitygroups/entity[@name=animalZombieVultureRadiated]/property[@name=prob=]/@value">0.00</set>

</config>

 
Use this @Jugginator:

<set xpath="/entitygroups/entitygroup/entity[@name=animalZombieVultureRadiated]/@prob">0.00</set>

 
Use this @Jugginator:
<set xpath="/entitygroups/entitygroup/entity[@name=animalZombieVultureRadiated]/@prob">0.00</set>
Thank you! I was close anyway haha. I see how that goes. Good thing too, going to do horde nigth tomorrow.

 
Do node specifiers have any sort of conditions such as greater/less than, or greater/less than or equal to? Eg.
[@value=>=60]
Yes you can, but you'll need to escape them

See below: the change willonly happen if the stage is greater than 23 and less than 153.

Code:
<append xpath='/gamestages/spawner[@name="BloodMoonHorde"]/gamestage[ @stage > 23 and @stage < 153]' >
	<spawn group="ZombiesNight" num="10" maxAlive="8"/>
</append>
 
I forgot what a... joy... modding could be.

What's wrong with this? The game tells me something starts with an illegal character.

<7DTDmod>

<set xpath="/recipes/recipe[@name=foodMeatStew]/ingredient[@name=foodRawMeat]/@count">5</set>

</7DTDmod>

I am trying to work my way through this thread, full of helpful stuff but there's so much more advanced than the level I'm at... any help appreciated, and I'll keep hammering away at my round hole with my square peg :D

 
Can anyone help, i'm trying to reduce the number of opened lootable items but it is not liking the ends-with?

Thanks

2018-11-27T21:21:34 12.869 ERR XML loader: Patching 'blockplaceholders.xml' from mod 'Better Balance Mod' failed

2018-11-27T21:21:34 12.869 EXC function ends-with not found

Code:
<!-- Reduce 'opened' lootable items -->
<set xpath="/blockplaceholders/*/block[ends-with(@name, 'Open')]/@prob">.8</set>
<set xpath="/blockplaceholders/*/block[ends-with(@name, 'Closed')]/@prob">.2</set>
 
I forgot what a... joy... modding could be.
What's wrong with this? The game tells me something starts with an illegal character.

<7DTDmod>

<set xpath="/recipes/recipe[@name=foodMeatStew]/ingredient[@name=foodRawMeat]/@count">5</set>

</7DTDmod>

I am trying to work my way through this thread, full of helpful stuff but there's so much more advanced than the level I'm at... any help appreciated, and I'll keep hammering away at my round hole with my square peg :D
Looked fine and a quick test it worked for me chaning the count to "1". You are adding it to recipes.xml?

\mods\modname\config\recipes.xml

 
Looked fine and a quick test it worked for me chaning the count to "1". You are adding it to recipes.xml?
\mods\modname\config\recipes.xml
I am.

I'll have another look tomorrow in case I've done something stupid, but that text there was copy/pasted directly from the recipes.xml file in Mods/7DTDmod/config

 
Back
Top