Skip to content

peteradrichem/Xul

Repository files navigation

Xul -- XML Utilities

PyPI version Wheel Python versions License Documentation Black code style Typing checked by mypy Ruff linting Imports sorted by isort Code checks

Xul scripts

Xul is a set of XML scripts written in Python.

  • ppx: pretty print XML
  • xp: select XML nodes with XPath
  • transform: transform XML with XSLT
  • validate: validate XML with XSD, DTD or RELAX NG

Installation

Xul command line scripts can be installed with pip:

$ pip install Xul

Install Pygments for XML syntax highlighting (optional).

$ pip install Xul[syntax]

Dependencies

Xul uses the excellent lxml XML toolkit, a Pythonic binding for the C libraries libxml2 and libxslt.

Documentation

Xul documentation can be found on Read The Docs.

Options

List the command-line options of a Xul script with --help. For example:

$ xp --help

usage: xp [-h] [-V] [-l | -L] [-d DEFAULT_NS_PREFIX] [-e] [-q] [-p] [-r] [-m] xpath_expr [xml_source ...]

Select nodes in an XML source with an XPath expression.

positional arguments:
  xpath_expr            XPath expression
  xml_source            XML source (file, <stdin>, http://...)

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -m, --method          use ElementTree.xpath method instead of XPath class

file hit options:
  output filenames to standard output

  -l, -f, --files-with-hits
                        only names of files with a result that is not false and
                        not NaN are written to standard output
  -L, -F, --files-without-hits
                        only names of files with a false or NaN result, or without a result,
                        are written to standard output

namespace options:
  -d DEFAULT_NS_PREFIX, --default-prefix DEFAULT_NS_PREFIX
                        set the prefix for the default namespace in XPath [default: 'd']
  -e, --exslt           add EXSLT XML namespaces
  -q, --quiet           don't print XML source namespaces

element output options:
  -p, --pretty-element  pretty print the result element
  -r, --result-xpath    print the XPath expression of the result element (or its parent)

W3C standards

Related