XML Replace - KeePass
Author: Dominik Reichl
Description: KeePass is an open source password manager. Passwords can be stored in highly-encrypted databases, which can be unlocked with one master password or key file.
Keywords: KeePass, Password, Safe, Security, Database, Encryption, Secure, Manager, Open, Source, Free, Code, Key, Master, Disk, Dominik, Reichl

| # XML Replace About the XML replacement functionality.

- General Information
- Usage Examples
  - Replace text in all entry titles and notes
  - Replace all HTTP URLs by HTTPS URLs
  - Replace group icons
  - Delete entry strings by name
  - Delete entry attachments by name extension
  - Reset background colors
  - Disable auto-type for entries with empty fields

## General Information

XML Replace is a powerful feature that modifies a database by manipulating its XML representation.

KeePass creates a KDBX XML DOM of the current database in memory, performs the operation specified by the user (e.g. remove nodes or replace text), tries to load the modified XML, and merges the current database with the modified database.

This is a feature for experts. Use with caution!

A few links that might be helpful for working with XPath and regular expressions:

- XPath:
  - Wikipedia: XPath
  - MSDN: XPath Reference
  - MSDN: XPath Examples
- Regular expressions:
  - MSDN: Regular Expression Language - Quick Reference

KeePass protects history entries; XML Replace cannot be used to modify these. Furthermore, any changes to database properties (database name/description, etc.) may be ignored.

## Usage Examples

Replace text in all entry titles and notes
Select nodes: | `//Entry/String[Key='Title' or Key='Notes']/Value`
Action: | Replace data
Data: | Inner text
Find what: | `TheTextToFind`
Replace with: | `TheReplacement`
Within all entry titles and notes, this replaces all occurences of `TheTextToFind` by `TheReplacement`.

Replace all HTTP URLs by HTTPS URLs
Select nodes: | `//Entry/String[Key='URL']/Value`
Action: | Replace data
Data: | Inner text
Find what: | `^http:`
Replace with: | `https:`
Regular expressions: | Activated
Within all entry URL fields, this replaces all HTTP URLs by HTTPS URLs.

Replace group icons
Select nodes: | `//Group/IconID`
Action: | Replace data
Data: | Inner text
Find what: | `^48$`
Replace with: | `36`
Regular expressions: | Activated
This assigns the ZIP package icon to all groups that currently have a closed folder as icon. All icon IDs can be found in the icon picker dialog.

Delete entry strings by name
Select nodes: | `//Entry/String[Key='TheName']`
Action: | Remove nodes
Removes all entry strings named `TheName`.

Delete entry attachments by name extension
Select nodes: | `//Entry/Binary[substring(Key, string-length(Key) - 3) = '.jpg']`
Action: | Remove nodes
Removes all entry attachments that have a name ending in '.jpg'. The '`3`' in the node selection XPath expression is the length of '`.jpg`' - 1. If you'd e.g. want to search for attachments that have a name ending in '`.abcde`', you'd need to replace the '`3`' by '`5`'.

Reset background colors
Select nodes: | `//Entry/BackgroundColor`
Action: | Remove nodes
Sets the background color of all entries to the default (transparent/alternating).

Disable auto-type for entries with empty fields
Select nodes: | `//Entry/String[(Key='UserName' or Key='Password') and Value='']/../AutoType/Enabled`
Action: | Replace data
Data: | Inner text
Find what: | `True`
Replace with: | `False`
Disables auto-type for all entries that have an empty user name field or an empty password field.