title: How to escape HTML attributes in strings.xml?
body: <p>I'm supplying XML strings files to Android developers and confused about escaping rules when using HTML styles.</p>
  
  <p><a href="http://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML" rel="nofollow">The documentation here</a> only talks about embedding <code>&lt;b&gt;</code>, <code>&lt;i&gt;</code> and <code>&lt;u&gt;</code> tags without escaping, but it also shows that you can use <code>Html.fromHtml</code> with any string of HTML.</p>
  
  <p>So how should a chunk of HTML like <code>&lt;font color="red"&gt;"Quote"&lt;/font&gt;</code> appear in the strings.xml file?</p>
  
  <p>As font tags can have attributes and quotes should be escaped, how should attribute quoting be handled? </p>
  
  <p>The following is invalid XML, so clearly this is wrong:</p>
  
  <pre><code>&lt;string name="eg_1"&gt;&lt;font color=\"red\"&gt;\"Quote\"&lt;/font&gt;&lt;/string&gt; 
  </code></pre>
  
  <p>Should just the XML attributes be left unescaped?</p>
  
  <pre><code>&lt;string name="eg_2"&gt;&lt;font color="red"&gt;\"Quote\"&lt;/font&gt;&lt;/string&gt; 
  </code></pre>
  
  <p>It's valid XML, but seems wrong to have different escaping rules in the string.</p>
  
  <p>Perhaps CDATA should be used to simply protect the entire string?</p>
  
  <pre><code>&lt;string name="eg_3"&gt;&lt;![CDATA[&lt;font color=\"red\"&gt;\"Quote\"&lt;/font&gt;]]&gt;&lt;/string&gt;    
  </code></pre>
  
  <p>Or even just escape it?</p>
  
  <pre><code>&lt;string name="eg_4"&gt;&amp;lt;font color=\"red\"&amp;gt;\"Quote\"&amp;lt;/font&amp;gt;&lt;/string&gt;
  </code></pre>