XML Catalog rewriteSystem precedence when multiple catalogs share the same systemIdStartString
0 reputation · 21 Apr 2020, 20:01 UTC
0 reputation · 21 Apr 2020, 20:01 UTC
The rewriteSystem element in OASIS XML Catalogs 1.1 maps a system identifier prefix to a replacement URI, which is useful for redirecting external entity references in a repeatable development environment. When a project combines multiple catalog files through a catalog preference file, delegate entries, or processor-specific catalog chains, the specification does not state which mapping applies if two catalogs contain rewriteSystem entries with the same systemIdStartString but different rewritePrefix values.
This creates a configuration boundary: major XML processors such as Apache XmlResolver, Xerces-XMLCatalog, and Saxon's catalog resolver appear to apply different ordering rules (for example, first-match, last-match, or most-specific prefix matching), though the exact precedence in each tool's current release may require verification. Without a defined rule, the same document can resolve to different local URIs depending on which processor or version is used, undermining deterministic builds.
Does OASIS XML Catalogs 1.1 define any normative ordering for rewriteSystem entries when multiple catalogs are combined, or is the precedence entirely implementation-defined? How do current versions of Apache XmlResolver, Xerces-XMLCatalog, and Saxon's catalog resolver resolve conflicting rewriteSystem prefixes, and is that behavior documented? What configuration pattern ensures deterministic rewriteSystem resolution across different XML processors without consolidating all mappings into a single catalog file?
34775 reputation · 21 Apr 2020, 21:50 UTC
The OASIS XML Catalogs 1.1 specification does not define a normative ordering for rewriteSystem entries that appear in different catalogs with identical systemIdStartString values. Matching rules are defined only within a single catalog (longest‑prefix match), so when catalogs are combined via catalogs, delegate or processor‑specific chains, the precedence of duplicate prefixes is implementation‑defined.
rewriteSystem entry it encounters (first‑match). This order is documented in the XmlResolver Javadoc for CatalogResolver.net.sf.saxon.lib.URIResolver with a catalog, but Saxon‑HE/P/E allow a custom CatalogResolver implementation that can change the order; the default Saxon distribution therefore behaves like first‑match.Because these rules are not mandated by the specification, they may change between minor releases, and the exact behavior should be verified for the versions in use.
systemIdStartString value unique across the entire catalog chain. This is the only processor‑agnostic guarantee.catalogs elements or chaining CatalogResolver instances explicitly.rewritePrefix values, load them in the exact order used by your build, and confirm the resolved URI with each processor. Enable catalog tracing (e.g., XmlResolver’s setDebug(true), Xerces’ -Dxml.debug.catalog=true, or Saxon’s -T) to see which catalog supplied the match.Requesting the exact processor versions and catalog‑chaining method would only change the recommendation if you needed to rely on a specific implementation’s order; otherwise, the safe pattern is to avoid duplicate prefixes or test the order per processor.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.