1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="author" content="Dominik Reichl" />
<meta name="DC.title" content="XML Replace - KeePass" />
<meta name="DC.creator" content="Dominik Reichl" />
<meta name="DC.type" content="Text" />
<meta name="DC.format" content="text/html" />
<meta name="DC.language" content="en" />
<meta name="DC.rights" content="Copyright (C) 2003-2019 Dominik Reichl" />
<meta name="robots" content="index, follow" />
<meta name="flattr:id" content="42rykv" />
<title>XML Replace - KeePass</title>
<base target="_self" />
<link rel="stylesheet" type="text/css" href="../../default.css" />
</head>
<body>
<!-- Org Pub: 2013-12-06 -->
<table class="sectionsummary"><tr><td width="68">
<img src="../images/b64x64_binary.png" width="64" height="64"
class="singleimg" align="left" alt="People" />
</td><td valign="middle"><h1>XML Replace</h1><br />
About the XML replacement functionality.
</td></tr></table>
<ul>
<li><a href="#info">General Information</a></li>
<li><a href="#ex">Usage Examples</a>:
<ul>
<li><a href="#repstr">Replace text in all entry titles and notes</a></li>
<li><a href="#tohttps">Replace all HTTP URLs by HTTPS URLs</a></li>
<li><a href="#repgrpicon">Replace group icons</a></li>
<li><a href="#delstr">Delete entry strings by name</a></li>
<li><a href="#delbinext">Delete entry attachments by name extension</a></li>
<li><a href="#resetbgcolor">Reset background colors</a></li>
<li>Auto-Type:
<ul>
<li><a href="#atdisable">Disable auto-type for entries with empty fields</a></li>
<li><a href="#atdelayupper">Convert <code>{DELAY=</code> to upper-case</a></li>
<li><a href="#ataddstddelay">Prepend <code>{DELAY=50}</code> to all sequences without a <code>{DELAY=</code></a></li>
<li><a href="#atmodstddelay">Change <code>{DELAY=</code> values</a></li>
<li><a href="#atrmvstddelay">Remove <code>{DELAY=<em>x</em>}</code> from all sequences</a></li>
<li><a href="#atresetifstddelay">Reset default sequences that contain <code>{DELAY=</code></a></li>
<li><a href="#ataddassoc">Add an auto-type association to all entries</a></li>
</ul></li>
<li><a href="#copyurls">Copy entry URLs into title fields</a></li>
<li><a href="#copytitles">Copy entry titles into empty user name fields</a></li>
<li><a href="#firstnotempty">Ensure first line is not empty</a></li>
</ul></li>
</ul>
<br />
<a name="info"></a>
<h2 class="sectiontitle">
<img src="../images/b16x16_help.png" class="singleimg" alt="Help" /> General
Information</h2>
<p>XML Replace is a powerful feature that modifies a database by manipulating
its XML representation.</p>
<p>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.</p>
<p><img src="../images/b16x16_warning.png" alt="Warning"
style="vertical-align: middle; height: 1em;" />
This is a feature for experts. Use with caution!</p>
<p>XML Replace can be invoked via 'Tools' → 'Database Tools' →
'XML Replace'.</p>
<p>A few links that might be helpful for working with XPath and
regular expressions:</p>
<ul>
<li>XPath:
<ul>
<li><a href="https://en.wikipedia.org/wiki/XPath"
target="_blank">Wikipedia: XPath</a></li>
<li><a href="https://msdn.microsoft.com/en-us/library/ms256115.aspx"
target="_blank">MSDN: XPath Reference</a></li>
<li><a href="https://msdn.microsoft.com/en-us/library/ms256086.aspx"
target="_blank">MSDN: XPath Examples</a></li>
</ul></li>
<li>Regular expressions:
<ul>
<li><a href="https://msdn.microsoft.com/en-us/library/az24scfc.aspx"
target="_blank">MSDN: Regular Expression Language - Quick Reference</a></li>
</ul></li>
</ul>
<p>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.</p>
<br />
<a name="ex"></a>
<h2 class="sectiontitle">
<img src="../images/b16x16_help.png" class="singleimg" alt="Help" /> Usage
Examples</h2>
<br />
<a name="repstr"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Replace text in all entry titles and notes</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/String[Key='Title' or Key='Notes']/Value</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code><i>TheTextToFind</i></code></td></tr>
<tr><td>Replace with:</td><td><code><i>TheReplacement</i></code></td></tr>
<tr><td colspan="2">Within all entry titles and notes, this
replaces all occurences of <code><i>TheTextToFind</i></code> by
<code><i>TheReplacement</i></code>.</td></tr>
</table>
<br />
<a name="tohttps"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Replace all HTTP URLs by HTTPS URLs</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/String[Key='URL']/Value</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code>^http:</code></td></tr>
<tr><td>Replace with:</td><td><code>https:</code></td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">Within all entry URL fields, this replaces all
HTTP URLs by HTTPS URLs.</td></tr>
</table>
<br />
<a name="repgrpicon"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Replace group icons</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Group/IconID</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code>^48$</code></td></tr>
<tr><td>Replace with:</td><td><code>36</code></td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">This assigns the ZIP package icon to all groups that
currently have a closed folder as icon.<br />
<br />
All icon IDs can be found in the icon picker dialog.</td></tr>
</table>
<br />
<!-- https://sourceforge.net/p/keepass/discussion/329221/thread/56a33495/ -->
<a name="delstr"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Delete entry strings by name</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/String[Key='<i>TheName</i>']</code></td></tr>
<tr><td>Action:</td><td>Remove nodes</td></tr>
<tr><td colspan="2">Removes all entry strings named
<code><i>TheName</i></code>.</td></tr>
</table>
<br />
<a name="delbinext"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Delete entry attachments by name extension</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/Binary[substring(Key, string-length(Key) - 3) = '.jpg']</code></td></tr>
<tr><td>Action:</td><td>Remove nodes</td></tr>
<tr><td colspan="2">Removes all entry attachments that have a name
ending in '.jpg'.<br />
<br />
The '<code>3</code>' in the node selection XPath expression is the length of
'<code>.jpg</code>' - 1.
If you'd e.g. want to search for attachments that have a name ending
in '<code>.abcde</code>', you'd need to replace the '<code>3</code>' by
'<code>5</code>'.</td></tr>
</table>
<br />
<a name="resetbgcolor"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Reset background colors</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/BackgroundColor</code></td></tr>
<tr><td>Action:</td><td>Remove nodes</td></tr>
<tr><td colspan="2">Sets the background color of all entries to the
default (transparent/alternating).</td></tr>
</table>
<br />
<a name="atdisable"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Disable auto-type for entries with empty fields</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/String[(Key='UserName' or Key='Password') and Value='']/../AutoType/Enabled</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code>True</code></td></tr>
<tr><td>Replace with:</td><td><code>False</code></td></tr>
<tr><td colspan="2">Disables auto-type for all entries that have an empty
user name field or an empty password field.</td></tr>
</table>
<br />
<a name="atdelayupper"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Convert <code>{DELAY=</code> to upper-case</th></tr>
<tr><td>Select nodes:</td>
<td><code>//DefaultSequence | //KeystrokeSequence</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code>{DELAY=</code></td></tr>
<tr><td>Replace with:</td><td><code>{DELAY=</code></td></tr>
<tr><td colspan="2">Converts all <code>{DELAY=</code> codes
within auto-type sequence overrides and associations to upper-case
(by default the case sensitivity option is turned off, thus the 'Find what'
text matches all cases).<br />
<br />
In KeePass 2.x, placeholders are case-insensitive. However, this XML Replace operation
may be useful as preparation for the following example (which matches
<code>{DELAY=</code> in a case-sensitive way).</td></tr>
</table>
<br />
<a name="ataddstddelay"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Prepend <code>{DELAY=50}</code> to all sequences without a <code>{DELAY=</code></th></tr>
<tr><td>Select nodes:</td>
<td><code>(//DefaultSequence | //KeystrokeSequence)[not(contains(., '{DELAY='))
and (. != '')]</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code>^(.*)$</code></td></tr>
<tr><td>Replace with:</td><td><code>{DELAY=50}$1</code></td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">Prepends a <code>{DELAY=50}</code> to all auto-type
sequence overrides and associations that do not contain any
<code>{DELAY=</code> already and are not empty.<br />
<br />
Note that the node selection is case-sensitive (independent of the data
case sensitivity option), thus you need to ensure that all
<code>{DELAY=</code> codes are upper-case before performing this operation.
This can e.g. be done using the XML Replace operation mentioned
<a href="#atdelayupper">above</a>.</td></tr>
</table>
<br />
<a name="atmodstddelay"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Change <code>{DELAY=</code> values</th></tr>
<tr><td>Select nodes:</td>
<td><code>//DefaultSequence | //KeystrokeSequence</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code>\{DELAY=[\d\s]*\}</code></td></tr>
<tr><td>Replace with:</td><td><code>{DELAY=50}</code></td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">Sets the values of all <code>{DELAY=</code> codes
within auto-type sequence overrides and associations to 50.</td></tr>
</table>
<br />
<a name="atrmvstddelay"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Remove <code>{DELAY=<em>x</em>}</code> from all sequences</th></tr>
<tr><td>Select nodes:</td>
<td><code>//DefaultSequence | //KeystrokeSequence</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code>\{DELAY=[\d\s]*\}</code></td></tr>
<tr><td>Replace with:</td><td><em>(Leave empty)</em></td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">Removes all <code>{DELAY=<em>x</em>}</code> codes from
all auto-type sequences.</td></tr>
</table>
<br />
<a name="atresetifstddelay"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Reset default sequences that contain <code>{DELAY=</code></th></tr>
<tr><td>Select nodes:</td>
<td><code>//DefaultSequence[contains(., '{DELAY=')]</code></td></tr>
<tr><td>Action:</td><td>Remove nodes</td></tr>
<tr><td colspan="2">If a sequence has been specified in the field
'Override default sequence' (in the entry dialog) and it contains
<code>{DELAY=</code>, the sequence is reset,
i.e. the option 'Inherit default auto-type sequence from group' is activated.</td></tr>
</table>
<br />
<a name="ataddassoc"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Add an auto-type association to all entries</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/AutoType</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Outer XML</td></tr>
<tr><td>Find what:</td><td><code></AutoType>\Z</code></td></tr>
<tr><td>Replace with:</td><td><code><Association><Window>* - Notepad</Window><KeystrokeSequence>{PASSWORD}</KeystrokeSequence></Association></AutoType></code></td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">Adds an auto-type association to all entries: the window title
'<code>* - Notepad</code>' is associated with the sequence '<code>{PASSWORD}</code>'.</td></tr>
</table>
<br />
<a name="copyurls"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Copy entry URLs into title fields</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner XML</td></tr>
<tr><td>Find what:</td><td><code>(?s)(<Key>Title</Key>\s*)(<Value>.*?</Value>|<Value\s*/>)(.*?<Key>URL</Key>\s*)(<Value>.*?</Value>|<Value\s*/>)</code></td></tr>
<tr><td>Replace with:</td><td><code>$1$4$3$4</code></td></tr>
<tr><td>Case-sensitive:</td><td>Activated</td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">Copies the entry URL into the title field of the
entry (overwriting any existing data in the title field).</td></tr>
</table>
<br />
<a name="copytitles"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Copy entry titles into empty user name fields</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/String[Key='UserName' and Value='']/..</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner XML</td></tr>
<tr><td>Find what:</td><td><code>(?s)(<Key>Title</Key>\s*?<Value>)(.*?)(</Value>.+?<Key>UserName</Key>\s*?)<Value /></code></td></tr>
<tr><td>Replace with:</td><td><code>$1$2$3<Value>$2</Value></code></td></tr>
<tr><td>Case-sensitive:</td><td>Activated</td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">Copies the entry title into the user name field of the
entry, if this field is empty.</td></tr>
</table>
<br />
<a name="firstnotempty"></a>
<table class="tablebox">
<colgroup><col width="20%" /><col width="80%" /></colgroup>
<tr><th colspan="2">Ensure first line is not empty</th></tr>
<tr><td>Select nodes:</td>
<td><code>//Entry/String/Value</code></td></tr>
<tr><td>Action:</td><td>Replace data</td></tr>
<tr><td>Data:</td><td>Inner text</td></tr>
<tr><td>Find what:</td><td><code>(?s)^(\r?\n)</code></td></tr>
<tr><td>Replace with:</td><td><code>--$1</code></td></tr>
<tr><td>Regular expressions:</td><td>Activated</td></tr>
<tr><td colspan="2">For all multi-line fields,
this inserts '<code>--</code>' into the first line of the field value,
if this line is empty and the value has at least two lines.
For example,<br />
<br />
<div style="font-family: monospace; background-color: #C6C6C6; display: block;"><br />
<br />
Sample data</div>
<br />
is replaced by<br />
<br />
<div style="font-family: monospace; background-color: #C6C6C6; display: block;">--<br />
<br />
Sample data</div></td></tr>
</table>
</body></html>
|