When is it required to escape characters in XML?

Viewed 50352

When should we replace < > & " ' in XML to characters like &lt etc.

My understanding is that it's just to make sure that if the content part of XML has > < the parser will not treat is start or end of a tag.

Also, if I have a XML like:

<hello>mor>ning<hello>

should this be replaced to either:

  • &lthello&gtmor&gtning&lthello&gt
  • &lthello&gtmor>ning&lthello&gt
  • <hello>mor&gtning<hello>

I don't understand why replacing is needed. When exactly is it required and what exactly (tags or text) should be replaced?

5 Answers
Related