title: What's the correct way to encode CR-LF line breaks in text/xml values?
body: <p>As opposed to application/xml files which could do anything, or normalizedString values which convert all whitespace sequences to a single space character, I'm asking here specifically in the context of text/xml files with string values. For the sake of simplicity, let's say I'm only using ASCII characters with a UTF8 encoded file.</p>
  
  <p>Given the following two-line text string I wish to represent in XML:</p>
  
  <pre><code>Hello
  World!
  </code></pre>
  
  <p>Which is the following bytes in memory:</p>
  
  <pre><code>0000: 48 65 6c 6c 6f 0d 0a 57 6f 72 6c 64 21 Hello..World!
  </code></pre>
  
  <p>According to RFC 2046, any text/* MIME type MUST (not should) represent a line break using Carriage Return followed by Linefeed character sequence. In that light, the following XML fragment should be right:</p>
  
  <pre><code>&lt;tag&gt;Hello
  World!&lt;/tag&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>0000: 3c 74 61 67 3c 48 65 6c 6c 6f 0d 0a 57 6f 72 6c &lt;tag&gt;Hello..Worl
  0010: 64 21 3c 2f 74 61 67 3c                         d!&lt;/tag&gt;
  </code></pre>
  
  <p>But I regularly see files like the following:</p>
  
  <pre><code>&lt;tag&gt;&lt;![CDATA[Hello
  World!]]&gt;&lt;/tag&gt;
  </code></pre>
  
  <p>Or, even stranger:</p>
  
  <pre><code>&lt;tag&gt;Hello&amp;xD;
  World!&lt;/tag&gt;
  </code></pre>
  
  <p>Where the &amp;0xD; sequence is followed by a single Linefeed character:</p>
  
  <pre><code>0000: 3c 74 61 67 3c 48 65 6c 6c 6f 26 78 44 3b 0a 57 &lt;tag&gt;Hello&amp;xD;.W
  0010: 6f 72 6c 64 21 3c 2f 74 61 67 3c                orld!&lt;/tag&gt;
  </code></pre>
  
  <p>What am I missing here? What's the correct way to represent multiple lines of text in an XML string value so that it can come out the other end unmolested?</p>