LinuxCommandLibrary

xmlcatalog

Manage XML catalogs

SYNOPSIS

xmlcatalog [OPTIONS] [CATALOG_FILE] [COMMAND] [ARGS]

Common commands include `add`, `del`, `convert`, `dump`, `resolve`, and `validate`.

PARAMETERS

`--help`
    Display a brief help message and exit.

`--version`
    Display the version information and exit.

`-v, --verbose`
    Output verbose processing information, showing progress and details of operations.

`--debug`
    Output extensive debugging information, useful for troubleshooting.

`--sgml`
    Instruct `xmlcatalog` to operate on SGML catalogs rather than XML catalogs. This changes the parsing and output formats accordingly.

`--noout`
    Do not output the resulting catalog to standard output after modifications. Useful when only side effects (like creating a file) are desired.

`--create`
    Create the catalog file if it does not exist. This option is necessary when performing operations on a non-existent catalog.

`--valid`
    Validate the resulting catalog against its schema after any modifications have been applied, ensuring its well-formedness and correctness.

`--quiet`
    Suppress all error messages and warnings, useful for scripting or when minimal output is desired.

`--sort`
    Sort the catalog entries alphabetically after modifications. This helps in maintaining a consistent and readable catalog file.

`CATALOG_FILE`
    The path to the XML or SGML catalog file upon which to perform operations. This is often `/etc/xml/catalog` or a local project-specific catalog.

`COMMAND`
    The specific operation to perform on the catalog. Examples include `add` (to add an entry), `del` (to delete an entry), `convert` (to change catalog format), `dump` (to view contents), `resolve` (to find an entity), and `validate` (to check integrity).

`ARGS`
    Additional arguments required by the chosen `COMMAND`, such as the type of entry (e.g., `public`, `system`, `uri`), public ID, system ID, or URI for commands like `add` or `resolve`.

DESCRIPTION

The `xmlcatalog` command is a utility provided by the `libxml2` library for managing OASIS XML Catalog files. These catalogs provide a mechanism to remap public identifiers, system identifiers, or URIs to local resources, effectively allowing XML processors to resolve external entities (like DTDs, XML Schemas, or stylesheets) without needing network access or relying on hardcoded paths.

It supports various operations: adding new entries, deleting existing ones, converting SGML catalogs to XML format, dumping the catalog contents, resolving specific entities, and validating the catalog itself. This tool is invaluable in development and deployment environments where XML documents need to be validated or processed against locally cached schemas or DTDs, providing robustness and performance benefits by decoupling resource location from their public identifiers. It's a key component for creating self-contained and efficient XML processing workflows.

CAVEATS

Catalogs can become complex; errors in configuration, such as incorrect identifiers or paths, can lead to unexpected entity resolution failures or difficulties in XML processing.

The `xmlcatalog` utility relies on the `libxml2` library, ensuring consistency with other `libxml2`-based tools but also coupling its functionality to that specific library's implementation of the OASIS XML Catalog specification. While `xmlcatalog` handles OASIS XML Catalogs, there are other catalog specifications (e.g., Apache XML Commons Resolver), and compatibility between different implementations might vary.

CATALOG ENTRY TYPES

`xmlcatalog` supports adding various types of entries, each serving a specific purpose in resolving XML entities:

  • `public`: Maps a public identifier (e.g., for DTDs) to a system identifier (typically a local file path or URI).
  • `system`: Maps a system identifier (a URI) to another system identifier (often a local file path).
  • `uri`: Maps a URI (or a URI prefix) to another URI (or local file path).
  • `rewriteSystem`: Rewrites a system identifier by replacing a specified prefix with another.
  • `rewriteURI`: Rewrites a URI by replacing a specified prefix with another.
  • `delegatePublic`, `delegateSystem`, `delegateURI`: Delegates the resolution of a set of identifiers/URIs (based on a prefix or public ID) to another catalog file. This allows for modular catalog management.

EXAMPLE USAGE

To add a public entry mapping an XHTML DTD public ID to a local file path in `/etc/xml/catalog`:
`

xmlcatalog --add public "-//W3C//DTD XHTML 1.0 Strict//EN" "file:///usr/share/xml/dtd/xhtml1/xhtml1-strict.dtd" /etc/xml/catalog
`

To resolve a system entity URI using a specific catalog file:
`
xmlcatalog --resolve system "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" /etc/xml/catalog
`

To dump the current contents of the system-wide XML catalog:
`
xmlcatalog --dump /etc/xml/catalog
`

To create a new catalog file and add a URI mapping to it:
`
xmlcatalog --create --add uri "http://example.com/schemas/" "file:///home/user/myproject/schemas/" my_project_catalog.xml
`

HISTORY

`xmlcatalog` is an integral part of the `libxml2` library, which was initiated by Daniel Veillard in 1999. It emerged as a response to the growing need for robust and efficient XML processing tools on Unix-like systems. The utility's development closely followed the evolution of the OASIS XML Catalog Specification, providing a standard-compliant way to manage external entity resolution. Its inclusion in `libxml2` solidified its role as a fundamental tool for developers working with XML, especially in environments where offline validation, controlled resource access, and efficient processing are critical. It has been a stable component of `libxml2` for many years.

SEE ALSO

Copied to clipboard