Web / Apache Axiom Interview questions
How is namespace resolution handled internally in Axiom?
Each OMElement tracks its own OMNamespace along with a list of namespace declarations made directly on that element; resolving a prefix to a URI (or vice versa) walks up the ancestor chain, checking each element's own declarations in turn, until a match is found or the root is reached with no match.
This mirrors how namespace scoping works in XML itself: a declaration on a parent is inherited by all descendants unless a descendant re-declares (or explicitly undeclares) that same prefix, and Axiom's resolution logic simply implements that same scoping rule when asked to resolve a name.
On serialization, Axiom's writer checks whether a namespace it needs to emit for a given element or attribute is already in scope from an ancestor before writing a fresh xmlns declaration - if it is, the writer skips the redundant declaration, which keeps generated XML noticeably more compact than naively re-declaring every namespace on every element.
This scope-aware behavior is one of the places where hand-built trees, assembled through OMFactory across several stitched-together fragments, can produce subtly different (though still correct) output than a straightforward parse-then-reserialize round trip - the exact placement of xmlns declarations can shift depending on how and where each fragment's namespaces were originally declared.
More Related questions...