XML interview question · Most asked
XML, JSON or YAML: how do you choose?
Summary
JSON for web and mobile APIs (simple data, native in JavaScript). YAML or TOML for human-edited configuration. XML for documents with markup (mixed content), standards that mandate it (finance, healthcare, publishing, Office/SVG), strict schema-validated contracts, namespaces for combining vocabularies, and XSLT/XQuery pipelines.
Longer Answer
Converting XML to JSON needs an explicit mapping: generic converters turn one element into an object and two into an array, and lose types.
Key Points
- JSON: APIs.
- YAML: config.
- XML: documents, standards, contracts.
- Explicit mappings when converting.
Deep dive: XML Tutorial: XML vs JSON vs YAML
Explanation
What interviewers look for
Context-based choice, not dogma.
More most-asked XML questions
- 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's the difference between well-formed and valid XML?
- What is an XXE attack and how do you prevent it?
- How would you process a 10 GB XML file?
- What is XML and where is it still used today?
- Which characters must be escaped in XML, and what is CDATA?