XML interview question · Most asked
What's the difference between well-formed and valid XML?
Summary
Well-formed means the document follows XML syntax: one root, properly nested and closed tags, quoted attributes, escaped special characters. Valid means it's well-formed and also conforms to a schema (DTD, XSD, RELAX NG). A parser must reject malformed XML; validation is an extra, optional step.
Longer Answer
Every valid document is well-formed, but not vice versa. In integrations, validate at the boundary so bad messages fail with clear reasons instead of breaking later processing.
Key Points
- Well-formed: syntax rules.
- Valid: also matches a schema.
- Malformed input is a fatal error.
- Validate at system boundaries.
Deep dive: XML Tutorial: Well-Formed XML
Explanation
What interviewers look for
Clear distinction and why validation matters for integrations.
More most-asked XML questions
- 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?
- How does XSLT work? Explain templates and apply-templates.
- 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?