Summary
The namespace-declaration pipeline in src/c14n/ns_inclusive.rs and src/c14n/ns_exclusive.rs contains duplicated filter/sort/render logic. This duplication introduces drift risk and makes future maintenance harder.
Proposed Refactoring
Extract the shared pipeline into a common helper function that accepts a prefix filter predicate:
- Inclusive C14N: predicate accepts all in-scope namespace bindings.
- Exclusive C14N: predicate accepts only visibly-utilized namespaces (plus any forced prefixes from the
InclusiveNamespaces PrefixList).
The helper would own the shared steps:
- Collect candidate namespace bindings for the current element.
- Apply the caller-supplied predicate to filter them.
- Suppress redundant declarations already present in the nearest output ancestor (
parent_rendered).
- Handle
xmlns="" undeclaration semantics.
- Sort declarations by prefix (empty prefix first, then lexicographic).
- Return the declarations list and the updated
rendered map.
Both InclusiveNsRenderer and ExclusiveNsRenderer would delegate to this helper, keeping only their predicate logic local.
Motivation
- Removes code duplication between the two renderers.
- Reduces risk of the two implementations drifting apart on shared semantics (e.g., sorting order,
xmlns="" suppression rules).
- Makes it easier to add C14N 1.1 or other future modes.
References
Out of Scope for PR #6
This is a follow-up refactoring task and was explicitly deferred from PR #6.
Summary
The namespace-declaration pipeline in
src/c14n/ns_inclusive.rsandsrc/c14n/ns_exclusive.rscontains duplicated filter/sort/render logic. This duplication introduces drift risk and makes future maintenance harder.Proposed Refactoring
Extract the shared pipeline into a common helper function that accepts a prefix filter predicate:
InclusiveNamespaces PrefixList).The helper would own the shared steps:
parent_rendered).xmlns=""undeclaration semantics.renderedmap.Both
InclusiveNsRendererandExclusiveNsRendererwould delegate to this helper, keeping only their predicate logic local.Motivation
xmlns=""suppression rules).References
Out of Scope for PR #6
This is a follow-up refactoring task and was explicitly deferred from PR #6.