Name

lxgrep — Find nodes in an XML document that match an XPath query

Synopsis

lxgrep [ -xmlns[:prefix]=uri ...] [ -l ] [ -w wrapper-qname ] [ query ] [ input-file ...]

Description

lxgrep is an XML version of the well-known unix grep program. Instead of finding lines containing text that matches a regular expression, it finds nodes (usually elements) that match an XPath query. The matching nodes are output separated by line breaks, and if there are multiple input-file arguments then an XML comment containing the file name is output before each set of matches.

The input-file arguments may be URIs instead of filenames. If no input-file arguments are given, standard input is used.

-xmlns[:prefix]=uri

binds a prefix (or the default namespace) to a URI for use in XPath queries.

-l

Instead of listing the matching items themselves just list the names of files that contain matching items.

-w wrapper-qname

By default the output will not be a well-formed XML document unless only a single element matches. The -w option specifies the name of an element to be wrapped around the matches so that the result will be well-formed.

Bugs

There should be an option to prevent any linebreaks being added to the output.

There should be an option to stream the input, or the program should itself detect when streaming is possible, ideally breaking the query into a streamable and non-streamable part.