xgrep.py is a Python 3 script for searching for elements in XML files, using
XPath 1.0 expressions.
The script is released 'as is' with no warranty under the GNU General Public License, version 2.0.
It requires the following Python 3 packages:
The lxml package internally calls the libxml2 and libxslt C libraries.
On Debian-based systems, the prerequisites can be installed as follows:
sudo apt-get install python3-blessings python3-lxml
xgrep.py [-c] [--count] [-i] [--indent] [-l] [--files-with-matches] [-L] [--files-without-match] [-m] [--matches] [-n] [--declare-ns] [-q] [--quiet] [-r <ns>] [--regex <ns>] <XPath expression> <XML file(s)> xgrep.py [-v] [--version] xgrep.py [-h] [--help]
xgrep.py outputs the matching parts of the XML files together with
their filenames and the XPath expression. If
-r <ns> is set, the
<ns>:test() can be
used in the XPath expression for matching regular expressions. The option
outputs only the matching parts, without filenames or XPath expressions. The
-i indents the matching parts, and the option
-n includes namespace
declarations. The options
-q mimic the behaviour of
GNU grep. The latter option suppresses any
output, but still returns the exit status (
0 if there are matches,
there are none, and
2 for errors).
Andreas Nolda (firstname.lastname@example.org)