Finding and replacing text in multiple files

The Find and Replace in Files option ( FindFind/Replace in Files... or the toolbar button Find/Replace in Files ) enables you to define "search for" or "search for and replace" operations across a number of files. The find works at line level, which means a find match cannot cover characters on more than one line. The replace operation can bind Perl 5 regular expression group variables ($1, $2, etc.) from the find match. For example to replace the tag with attributes called tag-name with the tag tag-name1 use as text to find <tag-name(\s+)(.*)> and as replace text <tag-name1$1$2>.

The encoding used to read and write the files is detected from the XML header or from the BOM. If a file does not have an XML header or BOM <oXygen/> uses the UTF-8 encoding for files of type XML, that is one of the extensions: xml, xsl, fo, xsd, rng, nvdl, nrl, sch, wsdl or an extension associated with the XML editor type, or the encoding configured for non XML files.

You can cancel a long operation at any time by pressing the Cancel button of the progress dialog displayed when the operation is executed.

Because the content of read-only files cannot be modified, the Replace operation will not process those files. For every such file, a warning message will be displayed in the output panel.

 

Figure 23.3. Find/Replace in Files

Find/Replace in Files

The dialog contains the following fields/options:

Text to Find

The target character string to search for.

Case Sensitive

When checked, operations are case sensitive.

Whole words only

When checked only whole occurrences of a word will be included in the operation.

Regular Expression

When checked allows using any regular expression in PERL syntax.

Restrict to XPath

The XPath 2.0 expression entered in this combo is used to restrict the search scope.

The content completion assistant helps in entering XPath expressions and offers proposals.

When an XPath is entered in this field only files with XML content type are searched, that is files with extensions that are associated with one of the editors: XML editor, HTML editor, XSL editor, XSD editor, WSDL editor, RNG editor, NRL editor, NVDL editor, Schematron editor, SVG editor, XPROC editor.

Enable XML search options

When this option is checked the dialog is enlarged and the XML search options are shown below. This option allows restricting the search domain to the checked XML component types.

When this checkbox is selected only files with XML content type are searched, that is files with extensions that are associated with one of the editors: XML editor, HTML editor, XSL editor, XSD editor, WSDL editor, RNG editor, NRL editor, NVDL editor, Schematron editor, SVG editor, XPROC editor.

The supported XML component types are as follows:

  • Element names - only the names will be searched, without '<', '/', '>' or white-spaces. e.g.: <element />

  • Element contents

  • Attribute names - only the names will be searched, without the leading or trailing white-spaces.

  • Attribute values - only the values will be searched, without single quotes(') or double quotes("). e.g.: 'value' or "value"

  • Comments - only the content will be searched, skipping '<!--', '-->'. e.g.: <!--Comment content-->

  • Processing Instructions (PIs) - only the content will be searched, skipping '<?', '?>'. e.g.: <?processing instruction?>

  • CDATA - only the content will be searched, skipping '<![CDATA[', ']]>'. e.g.: <![CDATA[cdata content]]>

  • Doctype

  • Entities

The two buttons Select All and Deselect All allow a simple activation and deactivation of all types.

[Note]Note

Please note that since searching in some XML component types is performed only on their content skipping some of their headers/footers(see the list above), even if all the XML component types are checked, some filtering is still performed. To completely disable it you have to uncheck Enable XML search options.

Replace with

The character string with which to replace the target. It may contain regexp group markers if the search expression is a regular expression and the regular expression checkbox is checked.

Make Backups with extension

In the replace process <oXygen/> makes backup files of the modified files. The default extension is *bak, but you can change extension as you prefer.

All opened files

Search in all files opened in <oXygen/> (regular files or DITA Maps). You will be prompted to save all modified files before any operation is performed.

Directory of the current edited file

The search is done in the directory of the file opened in the current editor panel. If there is no opened file this option is disabled in the dialog.

Scope of the current DITA Map

The search is done in all maps and topics referenced by the current edited DITA Map. If "Recurse referenced maps" is checked the references from the maps referenced in the main DITA map will also be searched in. If there is no opened DITA Map this option is disabled in the dialog. You will be prompted to save all modified files before any operation is performed.

Project Files

Search in all files from the current project.

Selected project files

Search only in the selected files of the current opened project

[Note]Note

The search is performed only on local files. If you have added to the project remote files from an FTP or WebDAV server these will be skipped from the search.

Specified Path

Choose the search path

Recurse subdirectories

The search is performed recursively in the sub-directories found in the specified directory path only when this option is checked.

Recurse subdirectories

When checked, the search is performed recursively in the sub-directories found in the specified directory path.

Include hidden files

When checked, the search is performed also in the hidden files.

Find All

Executes a find operation and returns the result list to the Message Pane

Replace All

Replaces all occurrences of the target contained in the specified files.

[Warning]Use this option with caution.

Global search and replace across all project files does not open the files containing the targets, nor does it prompt on a per occurrence basis, to confirm that a replace operation must be performed. As the operation simply matches the string defined in the find field, this may result in replacement of matching strings that were not originally intended to be replaced.