XML interview question · Most asked
How would you process a 10 GB XML file?
Summary
Stream it: lxml/ElementTree iterparse with clear() and deletion of processed siblings, PHP XMLReader expanding one record at a time, or Java StAX/SAX. Process in batches with checkpoints so a crash resumes, validate per record, and keep memory flat regardless of size.
Longer Answer
Plain iterparse without clearing still builds the full tree. Also consider asking the producer for incremental (delta) feeds.
Key Points
- Streaming parser.
- Clear processed elements.
- Batches and checkpoints.
- Per-record validation.
Deep dive: XML in Production: The 4 GB Product Feed
Explanation
What interviewers look for
The clearing detail and resumability.
More most-asked XML questions
- What's the difference between well-formed and valid XML?
- Explain XML namespaces and the default namespace.
- Your XPath query returns nothing, but the elements are clearly there. What's the likely cause?
- Compare DOM, SAX and StAX (or pull parsing).
- What is an XXE attack and how do you prevent it?
- What is XML and where is it still used today?
- Which characters must be escaped in XML, and what is CDATA?
- Compare DTD, XML Schema (XSD), RELAX NG and Schematron.