[Advice] XML diff help

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
aerojet029
Posts: 78
Joined: Tue, 20. Aug 13, 14:36
x4

[Advice] XML diff help

Post by aerojet029 » Tue, 11. Dec 18, 01:26

I looked at the xrebirth XML diff tutorial and a few other mods. the tweak works by replacing the wholefile, but when i try the diff method i can't get it working

Code: Select all

<wares>
	<ware id="workunit_busy" name="{20201,9901}" transport="workunit" volume="1" tags="workunit">
		<price min="126" average="126" max="126" />
		<production time="3600" amount="400" method="default" name="{20206,201}">
		<primary>
			<ware ware="foodrations" amount="450" />
			<ware ware="medicalsupplies" amount="270" />
		</primary>
		</production>
		<production time="3600" amount="400" method="paranid" name="{20206,301}">
		<primary>
			<ware ware="medicalsupplies" amount="270" />
			<ware ware="sojahusk" amount="286" />
		</primary>
		</production>
		<production time="3600" amount="400" method="teladi" name="{20206,401}">
		<primary>
			<ware ware="medicalsupplies" amount="270" />
			<ware ware="nostropoil" amount="228" />
		</primary>
		</production>
		<icon active="ware_workunit_busy" />
	</ware>
	<ware id="workunit_idle" name="{20201,9801}" transport="workunit" volume="1" tags="workunit">
		<price min="84" average="84" max="84" />
		<production time="3600" amount="400" method="default" name="{20206,201}">
		<primary>
			<ware ware="foodrations" amount="300" />
			<ware ware="medicalsupplies" amount="180" />
		</primary>
		</production>
		<production time="3600" amount="400" method="paranid" name="{20206,301}">
		<primary>
			<ware ware="medicalsupplies" amount="180" />
			<ware ware="sojahusk" amount="191" />
		</primary>
		</production>
		<production time="3600" amount="400" method="teladi" name="{20206,401}">
		<primary>
			<ware ware="medicalsupplies" amount="180" />
			<ware ware="nostropoil" amount="152" />
		</primary>
		</production>
		<icon active="ware_workunit_idle" />
	</ware>
	<ware id="x4ep1_jttware" name="{20201,101}" description="{20201,102}" factoryname="{20109,5201}" group="shiptech" transport="container" volume="15" illegal="antigone argon holyorder ministry paranid teladi">
		<price min="1" average="1" max="1" />
		<icon active="ware_advancedelectronics" video="wrs_advancedelectronics_macro" />
	</ware>
</wares>
trying to replace with this. wheat is not the final ware, but i'm just using it for testing.

Code: Select all

<diff>
	<add sel="/wares/ware[@id='workunit_busy']/production [@name='"{20206,201}"']/primary">
		<ware ware="wheat" amount="300" />
	</add>
</diff>
<diff>
	<add sel="/wares/ware[@id='workunit_busy']/production [@name='"{20206,301}"']/primary">
		<ware ware="wheat" amount="300" />
	</add>
</diff>
<diff>
	<add sel="/wares/ware[@id='workunit_busy']/production [@name='"{20206,401}"']/primary">
		<ware ware="wheat" amount="300" />
	</add>
</diff>
<diff>
	<add sel="/wares/ware[@id='workunit_idle']/production [@name='"{20206,201}"']/primary">
		<ware ware="wheat" amount="300" />
	</add>
</diff>
<diff>
	<add sel="/wares/ware[@id='workunit_idle']/production [@name='"{20206,301}"']/primary">
		<ware ware="wheat" amount="300" />
	</add>
</diff>
<diff>
	<add sel="/wares/ware[@id='workunit_idle']/production [@name='"{20206,401}"']/primary">
		<ware ware="wheat" amount="300" />
	</add>
</diff>
I feel like I'm making a really silly mistake

youdotkay
Posts: 7
Joined: Mon, 19. Dec 16, 23:43
x4

Re: [Advice] XML diff help

Post by youdotkay » Tue, 11. Dec 18, 02:00

Code: Select all

<diff>
<add sel = '/wares/ware[@id="workunit_busy"]/production[@method="teladi"]/primary' >
		<ware ware="wheat" amount="300" />
	</add>

<add sel = '/wares/ware[@id="workunit_busy"]/production[@method="anotherrace"]/primary' >
<ware ware="wheat" amount="300" />
</add>

</diff>

aerojet029
Posts: 78
Joined: Tue, 20. Aug 13, 14:36
x4

Re: [Advice] XML diff help

Post by aerojet029 » Tue, 11. Dec 18, 03:59

still didn't work for me. works perfectly when I have the whole file

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!--Last exported: 06.12.2018 11:26:28-->
	<!-- Working busy -->
<diff>
	<add sel = '/wares/ware [@id="workunit_busy"]/production[@method="default"]/primary' >
		<ware ware="wheat" amount="300" />
	</add>
</diff>
	<!-- Working idle -->
<diff>
	<add sel = '/wares/ware[@id="workunit_idle"]/production[@method="default"]/primary' >
		<ware ware="wheat" amount="100" />
	</add>
</diff>

aerojet029
Posts: 78
Joined: Tue, 20. Aug 13, 14:36
x4

Re: [Advice] XML diff help

Post by aerojet029 » Tue, 11. Dec 18, 04:03

figured out the mistake, hey thanks man btw!

Edit: this is what got my setup running (for reference)

Code: Select all

<diff>
<!-- Working busy -->
	<add sel = '/wares/ware [@id="workunit_busy"]/production [@method="default"]/primary' >
		<ware ware="wheat" amount="300" />
	</add>
	<add sel = '/wares/ware [@id="workunit_busy"]/production [@method="paranid"]/primary' >
		<ware ware="wheat" amount="300" />
	</add>
	<add sel = '/wares/ware [@id="workunit_busy"]/production [@method="teladi"]/primary' >
		<ware ware="wheat" amount="300" />
	</add>
<!-- Working idle -->
	<add sel = '/wares/ware [@id="workunit_idle"]/production [@method="default"]/primary' >
		<ware ware="wheat" amount="100" />
	</add>
	<add sel = '/wares/ware [@id="workunit_idle"]/production [@method="paranid"]/primary' >
		<ware ware="wheat" amount="100" />
	</add>
	<add sel = '/wares/ware [@id="workunit_idle"]/production [@method="teladi"]/primary' >
		<ware ware="wheat" amount="100" />
	</add>
</diff>
Last edited by aerojet029 on Tue, 11. Dec 18, 06:56, edited 1 time in total.

ZEFFEZ
Posts: 10
Joined: Thu, 6. Sep 18, 06:15
x4

Re: [Advice] XML diff help

Post by ZEFFEZ » Tue, 11. Dec 18, 05:12

How did you replace the entire file? I know how to do the other way but every time I tried to replace the whole thing it didn't work.

aerojet029
Posts: 78
Joined: Tue, 20. Aug 13, 14:36
x4

Re: [Advice] XML diff help

Post by aerojet029 » Tue, 11. Dec 18, 06:02

as long as the file structure is the same, you just drop the edited version there. what file are you working with?

SirNukes
Posts: 546
Joined: Sat, 31. Mar 07, 23:44
x4

Re: [Advice] XML diff help

Post by SirNukes » Tue, 11. Dec 18, 06:18

If you just drop in an edited xml file, all of the extension root child elements get appended to the original root. Full replacement can be done with a diff patch that replaces the root itself.

aerojet029
Posts: 78
Joined: Tue, 20. Aug 13, 14:36
x4

Re: [Advice] XML diff help

Post by aerojet029 » Tue, 11. Dec 18, 06:48

like for example?

Code: Select all

<root>
	<bar
		<apple
			origionalcode
		</apple>
	</bar>
<root>
becomes.

Code: Select all

<root>
	<bar
		<apple
			origionalcode
			edited code
		</apple>
	</bar>
<root>
am I understanding your post correctly?

aerojet029
Posts: 78
Joined: Tue, 20. Aug 13, 14:36
x4

Re: [Advice] XML diff help

Post by aerojet029 » Tue, 11. Dec 18, 06:53

instead you are saying to do this?

Code: Select all

<diff>
<replace sel = '/root' >
	<root>
		<bar
			<apple
				editedcode
			</apple
		</bar>
	<root>
</replace>
</diff>

User avatar
alexalsp
Posts: 1820
Joined: Fri, 18. Jul 14, 05:28
x4

Re: [Advice] XML diff help

Post by alexalsp » Tue, 11. Dec 18, 07:06

Code: Select all

<diff>
<replace sel = '//root/apple' >
			<apple>
				editedcode
			</apple
</replace>
</diff>

Code: Select all

<diff>
<replace sel = '/root/apple' >
			<apple>
				editedcode
			</apple
</replace>
</diff>

Code: Select all

<diff>
<replace sel = '//apple' >
			<apple>
				editedcode
			</apple
</replace>
</diff>
Depends on location.

In this form, it is better to replace the entire unit.

Code: Select all

<diff>
	<replace sel = '/wares/ware[@id="workunit_busy"]/price>
		<price min="126" average="126" max="126" />
		<production time="3600" amount="400" method="default" name="{20206,201}">
		<primary>
			<ware ware="foodrations" amount="450" />
			<ware ware="medicalsupplies" amount="270" />
			<ware ware="wheat" amount="300" />
		</primary>
		</production>
		<production time="3600" amount="400" method="paranid" name="{20206,301}">
		<primary>
			<ware ware="medicalsupplies" amount="270" />
			<ware ware="sojahusk" amount="286" />
		</primary>
		</production>
		<production time="3600" amount="400" method="teladi" name="{20206,401}">
		<primary>
			<ware ware="medicalsupplies" amount="270" />
			<ware ware="nostropoil" amount="228" />
		</primary>
		</production>
		<icon active="ware_workunit_busy" />
	</replace>
</diff>
Replace the entire unit.

Post Reply

Return to “X4: Foundations - Scripts and Modding”