XMLSED(1)

NAME
xmlsed - print XML document with pattern substitutions

SYNOPSIS
xmlsed [-EiP] [-I indent] pattern [- n replacement ...] [file ...]

DESCRIPTION
xmlsed reads an XML stream from the specified files, or the standard input if no files are specified, and prints its content to standard output, replacing elements matched by pattern (as described in xmltools(7)) with replacement.

  Options
The following options are available:

-E  Do not expand built-in and internal entities, as defined by the inline doctype of the document. By default, internally defined entities are expanded, and xmlsed will fail on undefined entities with an XML syntax error. When expansion is disabled, the entity and the character sequence it represents are considered distinct.

-I indent
    Set the basic indentation step to indent spaces. The default is two spaces. The following flags can be appended to the indent value:

    ‘a’ Print attribute key/value pairs on a lines by themselves.

    ‘t’ Use one horizontal tab as the indentation unit, rather than one space.

    If no value is specified, it is taken as 0, so that ‘a’ is equivalent to ‘0a’.

-i  Ignore case distinction when matching regular expressions. Equality operators are not affected by this flag.

-P  Do not discard all-whitespace elements. Also disable automatic indentation of output.

    Be warned: specifying -P effectively adds elements to the abstract XML tree as seen by xmlsed; thus, some patterns may behave differently: two elements separated only by white space are not adjacent when this flag is enabled.

  Replacement texts
Replacement texts are specified through the -1 to -9 pseudo-options. The digit corresponds to the index of the subpattern to replace. Subpatterns are indexed starting from 1, ordered according to their open brace; i.e. a nested subpattern will have a higher index.

xmlsed replaces each interval matched by a subpattern with the corresponding replacement text. If no replacement text is given, the matched interval is printed without change.

Replacement texts must be well-formed XML fragments.

Within a replacement text, a ‘$’ character followed by a digit stands for the interval matched by the corresponding subpattern, and will be substituted accordingly by xmlsed. A replacement text may only refer to the matched subpattern or subpatterns enclosed in it.

To print a literal ‘$’ character, the character entity ‘&#x24;’ can be used instead.

EXAMPLES
Swap two elements named ‘foo’ or ‘bar’:
    $ xmlsed '{{foo}%{bar}}' -1 '$3$2'

DIAGNOSTICS
The xmlsed utility exits with 0 if a replacement took place, 1 if no replacement took place, >1 if an error occurred.

SEE ALSO
xmlgrep(1), xmltools(7)

AUTHORS
Nhat Minh Lê <minh@NetBSD.org>

BUGS
CDATA blocks containing ampersand characters get corrupted when the -E flag is in effect. This is due to the hackish way in which xmlsed handles entities. Expat provides very little control over entity parsing, so these kind of tricks need to be done behind its back, which does not always produce good results.