[TUTORIAL] XML Patch Guide

The place to discuss scripting and game modifications for X Rebirth.

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

mbhm
Posts: 78
Joined: Wed, 21. Mar 07, 18:13
x4

Post by mbhm » Sun, 5. Jan 14, 10:16

I have an interesting experience:

When using my mod loading a game, that wasn't modded before, i get the error messages:
[timestamp: 1388912148]: Error: LookupKeyName::LookupName(): The key name "sel" is not recognized in lookup 'ScriptXML'. Originated from: ""
[timestamp: 1388912148]: Error: Error loading MD file extensions\SIG\md\Smalltalk.xml: Invalid root node
Despite that the mod works normally.

The File starts with:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<diff>
  <replace sel='/mdscript/cues/cue[@name="SmalltalkSectionHandler"]'>

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sun, 5. Jan 14, 10:28

the Game tries to interpret the xml as merge file first, which is not succesful (because it doesnt know how to use the nodes in there with this method). afterwards it applies this file as diff file.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

mbhm
Posts: 78
Joined: Wed, 21. Mar 07, 18:13
x4

Post by mbhm » Sun, 5. Jan 14, 10:41

So it's normal and nothing to worry about. Thank you.

danke
Posts: 146
Joined: Wed, 6. Nov 02, 20:31
x4

Post by danke » Mon, 6. Jan 14, 06:05

Source:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
  <bar> 
    <foo a="1"/> 
  </bar>
  </bar>
    <foo a="2"/> 
  </bar> 
</root>
Is there an XPath zu address the second foo (<foo a="2"/>)?
(<bar> is not unique.)

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Mon, 6. Jan 14, 06:13

for your example those would count:

/root/bar/foo[@a='2']
//bar/foo[@a='2']
//foo[@a='2']

as long as one of the sub-nodes has something unique the parent node doesnt need to be unique ;)

or you can also adress the nth node with this name using this mehthod:
/root/bar[2]/foo
although i would recommend the first method since its more reliable.

PS if you use an XML Editor it should have an "evaluate XPath"-function - if you are not sure that your XPath works then play around with that ;) in the end it should return only one result
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

danke
Posts: 146
Joined: Wed, 6. Nov 02, 20:31
x4

Post by danke » Mon, 6. Jan 14, 07:03

Thanks. The following XPaths are valid too:

/root/bar[2]
or
/root/bar[2]/foo

Edit: Ah. I see. You wrote the same.

brammie
Posts: 100
Joined: Thu, 19. Dec 13, 23:26

Post by brammie » Sun, 12. Jan 14, 04:03

just remember that bar[2] != bar[@a='2'],
the bar[2] is a referencee to the 2e bar child, the bar[@a=2] is all the bar's where the attribute a=2...

mbhm
Posts: 78
Joined: Wed, 21. Mar 07, 18:13
x4

Post by mbhm » Wed, 2. Jul 14, 09:17

An interesting thing i ran into:

What to do if you want to adress a node that compares a fixed value.
Like:

Code: Select all

<do_elseif value="param == 'xyz'">
going straight forward it would be like:

Code: Select all

<replace sel="/root/[whatever nodes]/do_elseif[@value='param == 'xyz'']" />
but i'm pretty sure that won't work. Do those inner single quotes get doubled [ '' ] or escaped [ \' ]?

User avatar
YorrickVander
Posts: 2689
Joined: Tue, 29. Oct 13, 21:59
x4

Post by YorrickVander » Wed, 2. Jul 14, 10:18

stackoverflow (<3 stackoverflow) has this to say

http://stackoverflow.com/questions/1240 ... g-function

Worth a try if /' doesn't work.
X Rebirth - A Sirius Cybernetics Corporation Product

Split irritate visiting pilot with strange vocal patterns.

lhotski
Posts: 82
Joined: Thu, 10. Oct 13, 17:10
x3ap

Post by lhotski » Sun, 20. Jul 14, 03:33

How to replace one attribute of multiple same name nodes in a config file, e.g. libraries/targetpoints.xml?

Part of source:

Code: Select all

<targetpoints>
  ...
  <pointlist macro="struct_bt_dv_water_destillery_macro" tags="ship_xs hack">
    <point x="-368.217" y="526.846" z="-2913.74" r="50" comment="surface"/>
    <point x="-364.932" y="504.835" z="-3094.52" r="50" comment="surface"/>
    <point x="-1426.63" y="680.695" z="62.918" r="50" special="1"
comment="surface"/>
    ...
  </pointlist>
  ...
</targetpoints>
Variations like

Code: Select all

<replace sel="//point/@r">500</replace>
both

Code: Select all

<replace sel="*/point/@r>500</replace>
does not work. I've seen the validation error in debug log:

Code: Select all

[=ERROR=] Cannot match path '//point/@r' in patch file 'extensions\simplehack\libraries\targetpoints.xml'. Skipping node.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sun, 20. Jul 14, 09:18

you can either use the method mentioned here before for adressing the nth node (here the 2nd):
//pointlist/point[2]/@r

or you find an unique attribute in them, which does not have to be the same as the one you want to modify (the 2nd from your example here, too ^^):
//pointlist/point[@z='-3094.52']/@r

alternatively try if the game now supporsts the msel extension, although i doubt it does..
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

lhotski
Posts: 82
Joined: Thu, 10. Oct 13, 17:10
x3ap

Post by lhotski » Sun, 20. Jul 14, 11:01

Thank you, UniTrader!

In such cases other ways for replace are too bulky IMHO. :( This is just example which not very often used, perhaps.

msel selector is not supported here as you said:

Code: Select all

<replace msel="//point/@r">500</replace>

[=ERROR=] Missing 'sel' attribute in 'replace' node in patch file 'extensions\simplehack\libraries\targetpoints.xml'. Skipping node.

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Sun, 21. Dec 14, 18:45

Probably a dumb question, but if I started with this:

Code: Select all

<root>
  <bar>
    <foo a="1"/>
    <foo a="2"/>
  </bar>
</root>
and wrote this:

Code: Select all

<diff>
  <replace sel="//bar">
    <bar>

    </bar>
  </replace>
</diff>
would it output this?

Code: Select all

<root>
  <bar>
  </bar>
</root>
or this?

Code: Select all

<root>
  <bar>
    <foo a="1"/>
    <foo a="2"/>
  </bar>
</root>
edit: forgot a <bar></bar>

User avatar
Litauen
Posts: 193
Joined: Fri, 22. Nov 13, 21:09
xr

Post by Litauen » Fri, 13. Feb 15, 23:23

Need help.

File /md/NPC_Staff.xml

Code: Select all

<cue name="SectionHandler" instantiate="true">
..
<actions>
..
<do_elseif value="event.param == 'cStaff_move'">
...
  <dismiss_control_entity actor="$actor" object="$actor.container" />
</do_elseif>
I need this

Code: Select all

  <dismiss_control_entity actor="$actor" object="$actor.container" />
to be like this:

Code: Select all

  <do_if value="$actor.iscontrolentity">			
    <dismiss_control_entity actor="$actor" object="$actor.container" />
  </do_if>
Tried, does not work:

Code: Select all

<replace sel="//dismiss_control_entity[@actor='$actor']" >
<replace sel="*/dismiss_control_entity[@actor='$actor']" >
<replace sel="//dismiss_control_entity" >
<replace sel="*/dismiss_control_entity" >
<replace sel='//cue[@name="SectionHandler"]/actions/do_elseif[@value="event.param == 'cStaff_move'"]/dismiss_control_entity' >
<replace sel='//cue[@name="SectionHandler"]/actions/do_elseif[@value="event.param == /'cStaff_move/'"]/dismiss_control_entity'  >
Changed quotes from ' to " and vice versa, etc etc etc

Nothing works. Please help.

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Fri, 13. Feb 15, 23:31

Hey Litauen,

only way I found to reliably do that is to do a <remove ... /> and <add ... />

Code: Select all

<remove sel="//dismiss_control_entity[@object='$actor.container']"/>

<add sel="[your xpath]">
  <do_if value="$actor.iscontrolentity">         
    <dismiss_control_entity actor="$actor" object="$actor.container" />
  </do_if>
</add>

User avatar
Litauen
Posts: 193
Joined: Fri, 22. Nov 13, 21:09
xr

Post by Litauen » Sat, 14. Feb 15, 11:51

Thank you. This seems to work:

Code: Select all

	<remove sel="//dismiss_control_entity[@object='$actor.container']"/>
	<add sel='//cue[@name="SectionHandler"]/actions/do_elseif[@value="event.param == &apos;cStaff_move&apos;"]' >
		<do_if value="$actor.iscontrolentity">			
			<dismiss_control_entity actor="$actor" object="$actor.container" />
		</do_if>
	</add>
&apos; covers single quotes inside string.

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Sat, 14. Feb 15, 11:55

Litauen wrote:&apos; covers single quotes inside string.
Oh cool. That I did not know. Thanks!

edit: Just noticed that this thread isn't stickied anymore. Is there a new XML Patch guide coming up?

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sat, 14. Feb 15, 12:36

its now linked in the Stickied Topic [Index] X Rebirth Tools, Tutorials and Resources because too many Stickies clutter up the top of the Forum - less is more here ;)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Sat, 14. Feb 15, 12:39

Agreed. Thanks for taking the time to explain.

User avatar
nidaren
Posts: 66
Joined: Wed, 27. Nov 13, 14:33
x4

Post by nidaren » Tue, 31. Mar 15, 20:52

Hey Everyone,

I have a question in regards to what is the best solution to use in the case of:

add but only if such node does not exist in xml and skip if it does, is that possible via diff ?

Post Reply

Return to “X Rebirth - Scripts and Modding”