XML interview question · Most asked

Compare DOM, SAX and StAX (or pull parsing).

Create a free account to save this page, take notes and track your progress. Sign in

Summary

DOM loads the whole document into a tree: easy random access and XPath, but memory grows with the document (often 5-10x the file). SAX pushes events (start element, text, end element) to callbacks: constant memory, forward-only, more state to manage. StAX/pull parsers let your code ask for the next event: constant memory with simpler control flow.

Longer Answer

Use DOM for configs and messages, streaming for large exports and feeds. Python's iterparse and PHP's XMLReader combine streaming with small subtrees.

Key Points

  • DOM: whole tree.
  • SAX: push events.
  • StAX: pull events.
  • Choose by size and access pattern.

Deep dive: XML Tutorial: DOM vs Streaming Parsers

Explanation

What interviewers look for

Memory trade-off and practical choice.

More most-asked XML questions

← All XML questions

Was this page helpful?