XML interview question · Most asked
Compare DTD, XML Schema (XSD), RELAX NG and Schematron.
Summary
DTD: the original, non-XML syntax, no data types or namespaces, and entity features that cause security issues. XSD: XML syntax, rich data types, namespaces, reuse, the enterprise standard. RELAX NG: simpler, readable grammar (compact syntax), used by DocBook, ODF and EPUB. Schematron: XPath-based rules with human messages for business constraints that grammars can't express.
Longer Answer
A strong setup combines a grammar (XSD or RELAX NG) for structure with Schematron for rules like "total equals the sum of lines", as used for EU e-invoicing (EN 16931).
Key Points
- DTD: legacy, untyped.
- XSD: types and namespaces.
- RELAX NG: simpler grammar.
- Schematron: business rules.
Deep dive: XML Tutorial: RELAX NG and Schematron
Explanation
What interviewers look for
Correct strengths and a combined approach.
More most-asked XML questions
- What's the difference between well-formed and valid XML?
- Explain XML namespaces and the default namespace.
- Compare DOM, SAX and StAX (or pull parsing).
- Your XPath query returns nothing, but the elements are clearly there. What's the likely cause?
- 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?
- Explain XPath axes and give examples of predicates.