title: When is it required to escape characters in XML?
body: <p>When should we replace <code>&lt; &gt; &amp; " '</code> in XML to characters like <code>&amp;lt</code> etc.</p>
  
  <p>My understanding is that it's just to make sure that if the content part of XML has <code>&gt; &lt;</code> the parser will not treat is start or end of a tag.</p>
  
  <p>Also, if I have a XML like:</p>
  
  <pre><code>&lt;hello&gt;mor&gt;ning&lt;hello&gt;
  </code></pre>
  
  <p>should this be replaced to either:</p>
  
  <ul>
  <li><code>&amp;lthello&amp;gtmor&amp;gtning&amp;lthello&amp;gt</code></li>
  <li><code>&amp;lthello&amp;gtmor&gt;ning&amp;lthello&amp;gt</code></li>
  <li><code>&lt;hello&gt;mor&amp;gtning&lt;hello&gt;</code></li>
  </ul>
  
  <p>I don't understand why replacing is needed. When exactly is it required and what exactly (tags or text) should be replaced?</p>