Web / Apache Axiom Interview questions
Explain the lifecycle of an OMElement from parsing to serialization?
An OMElement's life typically runs through a handful of distinct stages, tied closely to Axiom's deferred-building model rather than a simple linear parse-then-use flow.
- Reader creation - an
XMLStreamReaderis created over the input source. - Builder wrapping - a
StAXOMBuilder(viaOMXMLBuilderFactory) wraps that reader. - Root returned, incomplete -
builder.getDocumentElement()returns the root OMElement, butisComplete()is false; only the start tag has been consumed so far. - Lazy materialization - as the application navigates children/siblings, the builder pulls further StAX events and appends corresponding OM nodes.
- Completion - once every child has been visited (or
build()is called explicitly), the element's END_ELEMENT event is reached andisComplete()becomes true. - Mutation (optional) - the now-navigable tree can have nodes added, detached, or reordered like any in-memory structure.
- Serialization -
serialize()(caching, tree stays usable) orserializeAndConsume()(streaming, tree becomes unusable afterward) writes the final XML.
flowchart LR
A[Create XMLStreamReader] --> B[Wrap in StAXOMBuilder]
B --> C[getDocumentElement returns root, incomplete]
C --> D[App navigates children/siblings]
D --> E{isComplete?}
E -- No --> D
E -- Yes --> F[Optional mutation: add/detach nodes]
F --> G[serialize / serializeAndConsume]
The key thing an interviewer is usually probing for here is step 3-5: many candidates assume the returned root is already a complete tree the moment it's obtained, when in fact it's only as built as whatever's been navigated so far.
More Related questions...