XML interview question · Most asked

Which characters must be escaped in XML, and what is CDATA?

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

Summary

& and < must always be escaped (&amp;, &lt;) in text and attribute values; quotes must be escaped inside attribute values delimited by the same quote. CDATA sections (<![CDATA[ ... ]]>) let you write text literally; after parsing it's ordinary text, and CDATA can't contain ]]>.

Longer Answer

Named entities such as &nbsp; are HTML, not XML. The real lesson: never build XML by string concatenation; use a library that escapes for you.

Key Points

  • & and < always.
  • Quotes inside attributes.
  • CDATA = literal text, same result after parsing.
  • Use a builder, not string formatting.

Deep dive: XML Tutorial: Escaping, CDATA and Encoding

Explanation

What interviewers look for

Correct entities and the builder recommendation.

More most-asked XML questions

← All XML questions

Was this page helpful?