XML Diff and PatchA VS Code extension that automatically generates and applies RFC 5261-compatible XML patch files using XPath selectors, watching modified XML files and producing diffs on save. Originally developed for modding X4: Foundations (which uses RFC 5261 XML patches for game-data mods), the extension is fully generic and works with any XML workflow that follows the RFC 5261 patch format. Features
RequirementsSet Minimal workspace settings example
How folder pairs workEach pair in
Path resolutionWhen a modified file is saved:
When a diff file is saved (
For example, if Glob zippingA glob in either field multiplies the pair: each expanded directory becomes a separate watcher instance. Both lists are sorted alphabetically after expansion and then zipped index-by-index, so they must expand to the same count. If they differ, the extension cannot determine the correct correspondence and skips the whole pair with a warning. The typical pattern is a parallel directory structure where the same wildcard produces matching results in both fields:
Multiple pairs share the same Context Menu CommandsRight-click any XML file or folder in the Explorer to access the XML Diff and Patch submenu. All three commands are also available from the Command Palette (uses the active editor's file when no selection is made). Selecting a folder processes all XML files within it recursively.
After each run a notification reports how many files were processed, how many were skipped (no matching original or wrong folder role), and how many orphan diffs were deleted. Extension SettingsAll settings are under the Editing Folder Pairs
Option 1: Settings Sidebar Panel (recommended)Open the XML Diff and Patch panel in the Explorer sidebar. It shows your folder pairs grouped by scope (User, Workspace, or per Folder). Use the Add pair button to create a new entry, fill in the fields, and click Save. Existing pairs can be edited in-place or removed with the ✕ button.
Option 2: Edit
|
| Setting | Default | Description |
|---|---|---|
originalFolder |
"" |
Path to the vanilla/baseline XML folder. Required. |
folderPairs |
[] |
Array of { modifiedFolder, diffFolder, pathPrefix? } objects. |
watchMode |
"onSave" |
onSave: trigger on explicit save; onTheFly: trigger on any FS change (debounced); contextMenuOnly: disable auto-watching. |
debounceMs |
500 |
Debounce delay in ms for onTheFly mode. |
reflectDiffToModified |
true |
When a diff file is saved, apply it to the original to regenerate the modified file. |
passOtherFiles |
true |
Copy files not found in originalFolder as-is to the output folder. |
emptyDiffBehavior |
"delete" |
Action when diff produces no operations: write, delete, warn, or warnDelete. |
onlyFullPath |
false |
Always emit absolute XPath (no // shorthand). |
useAllAttributes |
false |
Include all attributes in XPath predicates, not just disambiguating ones. |
ignoreDiffInAttribute |
null |
Attribute name to ignore when comparing elements (e.g. "version"). |
xsdPath |
"./diff.xsd" |
Path to an XSD schema for validating generated diff files. Relative paths resolve from workspace root. |
validationFailBehavior |
"warn" |
On schema validation failure: warn (write anyway), error (skip write), or off (disable validation). |
showDiffEditorOnSave |
false |
Open a side-by-side diff editor after generating a diff file. |
allowDoubles |
false |
Skip duplicate-element guard when applying <add> operations during patch. |
debug |
false |
Enable verbose debug logging in the output channel. |
Troubleshooting
Output channel
All extension activity is logged to the XML Diff and Patch output channel. Open it via View → Output and select XML Diff and Patch from the dropdown. The channel shows which folder pairs were resolved, which files were processed, and any warnings or errors.
Enable debug logging
Set xmlDiffAndPatch.debug to true in your settings to enable verbose logging. Debug output includes the resolved paths for every file event, XPath generation steps, and raw diff operations: useful for diagnosing unexpected diffs or missing output files.
"xmlDiffAndPatch.debug": true
Remember to set it back to false (or remove it) once you are done: debug mode is noisy.
Common issues
| Symptom | Likely cause | Fix |
|---|---|---|
| Nothing happens on save | watchMode is contextMenuOnly, or no valid folder pair matched the saved file |
Check the Output channel for "not configured" or pair-skipped warnings; verify originalFolder and folderPairs are set. |
| "XML Diff+Patch: not configured" status bar warning | originalFolder is empty or folderPairs is empty/invalid |
Add at least one valid folder pair via the Settings sidebar or settings.json. |
| Folder pair skipped with a warning | Glob patterns in modifiedFolder and diffFolder expanded to a different number of directories |
Ensure both globs match the same count of directories; check the Output channel for the expanded lists. |
| File reported as skipped by a context menu command | The selected file is not inside the required watch folder for that command (see Context Menu Commands) | Select the file from the correct folder role (modifiedFolder or diffFolder). |
| Baseline file not found | pathPrefix is wrong, or originalFolder does not contain the expected sub-path |
Enable debug logging and check the resolved original → path printed in the Output channel. |
| XSD validation errors | Generated diff does not conform to the schema at xsdPath |
Review the diff file and the schema; set validationFailBehavior to "warn" to write the file anyway while investigating. |
X4: Foundations Usage
X4: Foundations uses RFC 5261 XML patches to allow mods to modify game data without replacing entire files. This extension automates the diff/patch cycle:
- Set
originalFolderto the extracted X4 game-data folder. - Add a folder pair pointing at your mod's source XML and the diff output directory.
- Edit and save your modified XML: the extension writes the RFC 5261 patch automatically.
- Include the diff files in your mod package.
Demo

License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Credits
- Egosoft - for the game itself (In fact - for the series of games)!
- Members of the x4_modding discord channel - for their answers, support, ideas, and inspiration!
Changelog
[0.5.0] - 2026-05-17
- Added
- Initial public version

