Read the path#

X4 uses a restricted selector language rather than all XPath. Check your game's libraries/diff.xsd; acceptance by an XPath editor does not prove X4 compatibility.

Form Meaning
/items/item item children of the items root
[@id='a'] Attribute filter
/@enabled The attribute itself
//item[@id='a'] Any depth; check uniqueness

Learning input#

These are invented data, not an X4 file:

XML
<items>
  <item id="a" enabled="false" />
  <item id="b" />
</items>

Independent patch:

XML
<diff>
  <replace sel="/items/item[@id='a']/@enabled">true</replace>
  <add sel="/items/item[@id='a']" type="@label">demo</add>
  <remove sel="/items/item[@id='b']" />
  <add sel="/items">
    <item id="c" />
  </add>
</diff>

Expected result#

XML
<items>
  <item id="a" enabled="true" label="demo" />
  <item id="c" />
</items>

replace changes an existing attribute, add type="@label" adds one, and remove deletes b. The final add inserts c inside items. This is an expected transformation, not log output or an executed game test.

Common mistakes#

Check one match for each operation. Replacing an entire element also removes its old children. To add an attribute, select the element through sel and name the attribute through type.

Do not rely on contains(), union | or arbitrary full XPath expressions. Investigate missing matches first: silent suppresses a report without fixing the path. Continue with a real ship patch and compatibility.