Using XML Catalogs for Offline Builds
XML catalogs enable offline build tools to achieve fully deterministic and reproducible builds by intercepting remote URI requests for external resources—such as Document Type Definitions (DTDs) and XML Schema Definitions (XSDs)—and resolving them to local file paths. Without internet access, standard XML parsers fail when attempting to fetch remote schemas declared in XML headers. By supplying a pre-configured, local mapping file adhering to the OASIS XML Catalog standard, build tools ensure that parsing, schema validation, and XSLT transformations execute identically across any environment without querying external networks.
The Problem of Network-Dependent XML Parsing
When an XML processor encounters an external entity reference, such as a DTD declaration:
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">its default behavior is to fetch the resource from the specified HTTP/HTTPS URL. In an isolated, air-gapped, or offline continuous integration (CI) pipeline, these outgoing network requests fail, halting the build. Even with network access, relying on remote endpoints introduces latency, transient network failures, and potential non-determinism if the remote server modifies the schema or becomes unavailable.
How XML Catalogs Resolve External Entities Locally
An XML catalog is a standard XML document that defines mapping rules between external identifiers and local storage paths. Catalogs primarily resolve two types of identifiers:
- Public Identifiers (
PUBLIC): Formal Uniform Resource Names (URNs) that uniquely name a resource regardless of location. - System Identifiers (
SYSTEM): Direct URIs typically pointing to remote network locations.
A standard catalog.xml file uses mapping directives such
as <public> and <system>:
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<public
publicId="-//OASIS//DTD DocBook XML V4.5//EN"
uri="schemas/docbook-4.5/docbookx.dtd"/>
<system
systemId="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
uri="schemas/docbook-4.5/docbookx.dtd"/>
<rewriteURI
uriStartString="http://www.w3.org/2001/"
rewritePrefix="schemas/w3c/"/>
</catalog>When an XML parser is configured to use this catalog, it evaluates public and system IDs against the mapping table before issuing any I/O requests. If a match is found, the parser immediately substitutes the remote URI with the designated local file path.
Integrating Catalogs into Offline Build Workflows
Offline build engines (such as Maven, Gradle, Ant, or native
command-line tools like xsltproc and xmllint)
utilize XML catalogs through specific configuration steps:
Vendoring Schemas: All required DTD, XSD, and XSLT files are packaged directly into the source control repository or provided as a hermetic, pre-downloaded dependency archive.
Configuring the Entity Resolver: Build plugins configure the underlying XML parser (e.g., Apache Xerces, Saxon, or libxml2) to use an OASIS-compliant
EntityResolverorURIResolver.Setting Environment Variables or CLI Flags: Command-line processors are explicitly pointed to the catalog. For example,
libxml2-based tools leverage theXML_CATALOG_FILESenvironment variable:export XML_CATALOG_FILES="/path/to/project/catalog.xml" xsltproc --nonet stylesheet.xsl document.xmlThe
--nonetflag enforces strict offline execution by causing the build to fail explicitly if any unmapped resource attempts a network connection.
Core Benefits for Determinism and Reliability
- Hermetic Execution: The build is isolated from third-party hosting infrastructure, guaranteeing that builds do not break due to server downtime or decommissioned URIs.
- Bit-for-Bit Reproducibility: Every build run processes identical schema versions and entity definitions, eliminating unexpected validation changes over time.
- Performance: Eliminating network overhead during XML parsing reduces transformation and validation times to purely local disk and memory speeds.
- Enhanced Security: Blocking automatic URI retrieval mitigates risks associated with Server-Side Request Forgery (SSRF) and XML External Entity (XXE) attacks during compilation phases.