Skip to content

Metadata manipulator: SimpleReplace

Mark Jordan edited this page Sep 21, 2016 · 13 revisions

Overview

This metadata manipulator performs simple search and replace on MODS data.

Toolchains

Can be used within any toolchain (i.e., is not specific to CONTENTdm CSV, etc.) that uses a MODS metadata parser.

Configuration

To register this manipulator in your toolchain, add an entry similar to the following to the "[MANIPULATORS]" section of your .ini file:

metadatamanipulators[] = "SimpleReplace|/pattern/|replacement text"

e.g. in my use case:

metadatamanipulators[] = "SimpleReplace|/<title>Page/|<title>Part"

Some additional examples include:

  • `metadatamanipulators[] = "SimpleReplace|/<roleTerm\stype="text">photographer/|<roleTerm type="text">Creator"
  • metadatamanipulators[] = 'SimpleReplace|/<identifier\stype="local"\sdisplayLabel="Local\sidentifier">image(\d\d)<\/identifier>/|<identifier type="local" displayLabel="Local number">Number $1</identifier>'

Parameters

This manipulator takes twoparameters:

  • The first parameter (required) is the pattern to match on. This pattern is a PHP Perl Compatible Regular Expression, without any leading or trailing quotation marks.
  • The second parameter (required) is the replacement text.

Functionality

Unlike other metadata manipulators that apply to MODS toolchains, this metadata manipulator does not manipulate the PHP DOM. Instead, it performs preg_replace() operations directly to the incoming XML fragment. Therefore, to make matches (and corresponding replacements) as precise as possible, you should include in your pattern any contextual string data that will limit the search and replace to only the elements you want to modify. In the example above, Page will only be replaced with Part if it occurs immediately following the <title> markup.

If this manipulator modifies an XML fragment, it writes an entry to the manipulator log indicating the record key plus the before and after fragment, like this:

[2016-09-20 14:53:02] config.INFO: SimpleReplace {"Record key":"90","Input":"<titleInfo><title>Page 1</title></titleInfo>","Modified version":"<titleInfo><title>Part 1</title></titleInfo>"} []
Clone this wiki locally