---
title: XML selectors: add, replace and remove by example
summary: Read sel, add an attribute and inspect the expected patched document.
section: scripting
kind: guide
status: example
updated: 2026-10-27
tags: ["X4","modding","xpath","selectors"]
sources: ["https://chemodun.github.io/x4/modding-support/anatomy-of-an-extension/xml-diff-patching/","https://datatracker.ietf.org/doc/html/rfc5261"]
---
## 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
```
Independent patch:
```xml
true
demo
```
## Expected result
```xml
```
`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](wiki:editing-parameters) and [compatibility](wiki:compatibility).